March 24, 20266 min read

Understanding GIF Color Tables and Dithering

A deep dive into how GIFs store color information, why the 256-color limit exists, and how dithering makes GIFs look better despite that constraint.

gifcolorditheringtechnical

Why GIFs are limited to 256 colors

The GIF format was designed in 1987, when 8-bit color (256 colors per image) was standard for personal computers. The format uses a color table — an indexed palette — where each pixel stores not an RGB value but an index (0–255) into a list of up to 256 colors.

This design choice made GIF files compact for the era. Each pixel is one byte, and the LZW compression algorithm works very efficiently on indexed pixel data. The trade-off is that GIFs can't represent photographic content with fine color gradations — that's why GIFs look great for simple graphics and terrible for photos.

Global vs local color tables

A GIF file can have two types of color tables:

  • Global Color Table (GCT): One palette shared by all frames. Up to 256 colors for the entire animation.
  • Local Color Table (LCT): A separate palette per frame. Each frame can have up to 256 unique colors, allowing more total colors across the animation at the cost of file size.

You can inspect a GIF's palette structure using GifMash's Color Palette Analyzer. Most web GIFs use a global color table; professionally optimized GIFs sometimes use per-frame tables to maximize color fidelity.

How color count affects file size

The color table itself is small (256 colors × 3 bytes = 768 bytes), but the color count has a large indirect effect on compression. LZW compression works by finding repeating patterns in the pixel index stream. With fewer unique colors (say, 64 instead of 256), pixel indices repeat more frequently, creating longer repeating patterns that compress to fewer bytes.

In practice: reducing from 256 to 128 colors typically saves 15–25% file size; reducing to 64 colors saves 30–45%. Below 64 colors, quality degradation becomes visible in most images.

What is dithering?

When you reduce a full-color image to 256 (or fewer) indexed colors, some colors in the original have no exact match in the palette. Dithering is a technique that approximates missing colors by mixing palette colors at the pixel level — similar to how printing presses mix ink dots.

The most common algorithm, Floyd-Steinberg dithering, distributes quantization error to neighboring pixels. The result is a pattern of mixed pixels that creates the perception of in-between colors, at the cost of slightly larger file size (the noise in the pattern is harder for LZW to compress).

Dithering trade-offs

Without dithering, color-limited GIFs show visible banding — sharp boundaries where one color transitions to another. With dithering, gradients look smoother but you get a grainy, noisy texture.

  • Use dithering for: photographs, gradient backgrounds, images with many subtle color transitions
  • Skip dithering for: logos, text, flat-color illustrations, pixel art — dithering adds noise and increases file size without benefit

Gifsicle's lossy mode and color tables

Gifsicle's --lossy flag deliberately introduces small artifacts to improve LZW compression. At the pixel level, it modifies pixel values to create longer repeating patterns in the index stream. This is separate from color table reduction — you can use both together for maximum compression.

GifMash combines color table reduction (via --colors N) and optional lossy compression to achieve up to 80% size reduction while keeping the animation visually acceptable.

Analyze GIF colors

Use GifMash's GIF Color Palette Analyzer to see every color in your GIF's palette.

Try it free