PDFMove
Why Is GIF So Big? 256 Colors, LZW and Frame Structure
Guide

Why Is GIF So Big? 256 Colors, LZW and Frame Structure

7 min read

GIF is a format designed in 1987 and it has barely changed since. It's still widely used today, but next to modern alternatives it's dramatically inefficient. This article looks inside the format to explain why it produces such large files and where it still makes sense.

The palette-based color model

GIF's most defining characteristic is how it stores color.

In modern image formats each pixel carries its own color value: 8 bits of red, 8 bits of green, 8 bits of blue — roughly 16.7 million possible colors.

GIF works differently. It keeps a color table (palette) and each pixel records an index into that table. The palette can hold at most 256 entries.

Palette:
  0 → #000000 (black)
  1 → #FF0000 (red)
  2 → #00FF00 (green)
  ...
  255 → #FFFFFF (white)

Pixel data: 0, 0, 1, 1, 2, 0, 255, ...

The advantage: each pixel takes 8 bits instead of 24. In 1987's memory conditions that was a serious win.

The disadvantage: the image can contain at most 256 distinct colors.

The visual cost of 256 colors

A video frame typically contains tens of thousands of distinct colors. Reducing that to 256 requires color quantization — an algorithm analyzes the colors in the image, picks the 256 most representative ones, and maps every pixel to the nearest palette entry.

The visible consequences:

Banding. A smooth gradient — sky, a light transition, a shadow — turns into flat bands of color. Continuity is lost and a stepped appearance emerges.

Skin tone distortion. Human faces contain many close tones and the palette struggles to separate them. The result is a blotchy, sickly appearance.

Color shift. Colors without an exact match in the palette get rounded to the nearest neighbor; your brand's corporate blue can drift to a slightly different blue.

Results vary by content type:

| Content | Result at 256 colors | |---|---| | Screen recording, interface | Usually good (few colors to begin with) | | Cartoon, illustration | Good | | Text and graphics | Very good | | Nature footage | Noticeable banding | | Human face, skin | Blotchy | | Night scene, gradient | Bad |

Dithering: a visual trick

Dithering is used to soften banding. The idea: by scattering two palette colors across neighboring pixels, you create the impression from a distance of seeing the tone in between.

It's the same principle newspaper photographs use to create gray tones out of black dots.

Dithering noticeably improves visual quality — bands disappear, gradients smooth out. But it has a cost, and that cost shows up directly in file size.

LZW compression and the dithering contradiction

GIF uses a lossless compression scheme called LZW (Lempel-Ziv-Welch). LZW finds repeating patterns in the data and replaces them with short codes. A run like "0,0,0,0,0,0" gets encoded very compactly.

This works very well on images containing flat color areas — logos, charts, interface screenshots.

Now think about what dithering does: it makes flat areas deliberately noisy. Instead of "0,0,0,0,0,0" you get a pattern like "0,1,0,1,1,0".

LZW can't find repetition in that noise. Compression efficiency drops and the file grows.

So dithering improves visual quality but also increases file size. When producing a GIF you have to balance the two.

Inter-frame optimization: a limited mechanism

GIF stores animation as a sequence of frames. Each frame can have its own duration (delay value) and its own palette.

The format offers some optimization:

Partial frames. A frame can contain only a changed rectangular region rather than the whole image. In an animation with a static background this saves a lot.

Transparent pixels. Unchanged pixels can be marked transparent so the previous frame shows through.

Disposal method. Specifies what happens to the current frame before the next one: keep it, restore to background, restore to previous.

These help, but they stay primitive next to modern video codecs. The reason: GIF doesn't know the concept of motion.

A video codec can detect that an object shifted 12 pixels to the right and say "take that block from the previous frame, move it 12 pixels right" — a few bytes. GIF can only say "this rectangular region changed, here are its new pixels" — thousands of bytes.

When there's a moving camera or a scene transition, partial-frame optimization becomes completely useless; every pixel changes in every frame.

A comparison in numbers

For the same 5-second, 480×270 pixel, 15 fps content, roughly:

| Format | Typical size | Color | |---|---|---| | GIF | 3-8 MB | 256 | | Animated WEBP | 800 KB - 2 MB | Full color | | APNG | 2-5 MB | Full color + alpha | | MP4 (H.264) | 200-500 KB | Full color | | WEBM (VP9) | 150-400 KB | Full color |

MP4 carries the same content at roughly a tenth of GIF's size and at much better color quality. That gap isn't a small optimization, it's a categorical advantage.

The three factors that determine file size

GIF size grows with the product of three variables:

Duration × frame rate = total frame count. 10 seconds × 20 fps = 200 frames. 5 seconds × 12 fps = 60 frames. One third.

Resolution = pixels per frame. Halving the width reduces total pixels to a quarter.

Multiply them out:

  • 10 s, 20 fps, 800×450: 200 frames × 360,000 pixels = 72 million pixels
  • 5 s, 12 fps, 400×225: 60 frames × 90,000 pixels = 5.4 million pixels

About a 13-fold difference. That's why, when reducing GIF size, you need to address all three settings rather than just one.

A fourth factor: the amount of motion. A static scene benefits from partial-frame optimization and comes out very small. A scene with camera movement ends up many times larger at the same settings.

Why modern alternatives aren't catching on

Animated WEBP and APNG are superior to GIF in every way: full color, alpha transparency, much better compression. All modern browsers support them.

What keeps them from spreading isn't technical, it's ecosystem habit:

  • Messaging apps treat GIF as a special type and offer search libraries.
  • Forum software and wiki systems know GIF tags.
  • Email clients display GIF animation (they don't play video).
  • People say "send a GIF"; nobody says "send an animated WEBP."

There's an irony here: many platforms convert your uploaded GIF to MP4 behind the scenes and serve it back to you as a GIF. So when you say "I'm sharing a GIF," you're actually sharing video.

The right approach on the web

If you want to show an animation on your own website, there's no reason to use GIF:

<video autoplay muted loop playsinline>
  <source src="animation.webm" type="video/webm">
  <source src="animation.mp4" type="video/mp4">
</video>

This gives you exactly the same behavior as a GIF — no sound, plays automatically, loops forever — at a tenth of the size and at full color quality.

The playsinline attribute stops the video from going full screen on mobile browsers; it's required for GIF-like behavior.

In terms of page speed the difference is dramatic: a 400 KB video instead of a 5 MB GIF noticeably shortens load time.

Where GIF is still the right answer

  • Environments that don't support video: some forum software, older wiki systems.
  • Email: most clients don't play video but do display GIF (some show only the first frame).
  • The GIF libraries built into messaging apps.
  • Simple, low-color animations: loading indicators, small icon animations — here the 256-color limit isn't a problem anyway and GIF comes out at a reasonable size.

In summary

GIF works with a 256-color palette-based model, and that causes banding and blotchiness on photographic content; dithering visually softens this but reduces LZW's compression efficiency and grows the file. The format exploits inter-frame redundancy only in a primitive way — it has no concept of motion, it can only store changed rectangular regions. The result is that it takes about ten times the space of modern video codecs for the same content. Because file size grows with the product of duration, frame rate and resolution, any effort to shrink it must address all three. And for web use there's nothing technically defensible left about GIF: an autoplay muted loop video does the same job far better.

Frequently Asked Questions

Is GIF a lossless format?

In terms of compression, yes — LZW is lossless. But in terms of color there's serious loss: the 256-color limit dramatically simplifies a source with millions of colors. So GIF 'stores the 256-color image it's given without damaging it,' but the step of getting down to those 256 colors is already a big loss. In practice, GIF behaves like a lossy format for photographic content.

Does GIF not exploit redundancy between frames at all?

It does, in a limited way. A frame can be a small rectangle drawn over the previous frame containing only the changed region, and unchanged pixels can be left transparent. But that's very primitive next to the prediction modern video codecs do with motion vectors; GIF can't understand that an object has moved, it can only say 'this rectangle changed.'

Why does dithering make the file bigger?

Dithering scatters neighboring pixels in different colors to create the impression of more colors than the limited palette holds. That turns flat color areas into a noisy texture. Because LZW compression profits from repeating patterns, this artificial noise seriously reduces compression efficiency. Visual quality goes up, and so does file size.

Can APNG and animated WEBP replace GIF?

Technically both are far superior to GIF: they offer full color, alpha transparency and better compression. Animated WEBP typically stores the same content at a third of GIF's size. What keeps them from spreading is ecosystem habit — messaging apps, forums and email clients still treat GIF as a special case.

Try this out right away with Video → GIF.

Try Video → GIF