Most GIF problems stop being mysterious once you know four things about the format. It is old — finalised in 1989, unchanged since — and every odd behaviour traces back to decisions made for 2400-baud modems.
1. A GIF is a stack of images, not an image
An animated GIF is a sequence of sub-images sharing one canvas. Each frame has its own position, its own size, and optionally its own 256-colour palette. A well-optimised GIF is not a sequence of full frames — it is an initial full frame followed by small patches that say "draw these 40×30 pixels at (120, 64) and leave everything else alone".
This is why opening a GIF in a normal image editor gives you only the first frame: the editor reads it as one image, because structurally the first frame is one image.
2. 256 colours, chosen per frame
GIF uses 8-bit indexed colour: each pixel stores an index into a palette of at most 256 colours, and each palette entry is 24-bit RGB. There are no gradual alpha values — a pixel is either fully transparent or fully opaque.
So converting a photograph to GIF is inherently lossy: millions of colours are mapped onto 256. The mapping is called quantisation, and how well it is done determines whether your gradient becomes a smooth approximation or a set of stripes. Good quantisers minimise perceived error rather than raw RGB distance, because the eye is much more sensitive to brightness error than to colour error.
Dithering is the other half of the trick. Instead of mapping a pixel to the nearest palette colour, you alternate between two nearby colours in a pattern; at a distance, the eye averages them into the colour you wanted. It is a perceptual hack that works remarkably well — and it is also why dithered GIFs compress badly, because a noise pattern has no repeated sequences for LZW to find.
3. LZW compresses indices, not pixels
GIF's compression is LZW (Lempel–Ziv–Welch), a dictionary coder: it scans the index stream and replaces repeated sequences with short codes. It is fast and lossless, and it is the only compression in the format.
Critically, it operates on one frame at a time. There is no inter-frame prediction, no motion vectors, no "this block moved three pixels". A 20-frame GIF of a static scene where one pixel blinks stores twenty complete images.
That single design decision explains why GIFs are 5–10× larger than MP4s of the same clip, and why every big platform re-encodes them to video on upload.
4. Disposal methods decide what happens between frames
Because frames are patches on a shared canvas, the format needs a rule for what to do with the previous frame before drawing the next. That rule is the disposal method, and getting it wrong is the most common cause of smeared, trailing, or flickering output.
| Value | Name | Behaviour |
|---|---|---|
| 0 | Unspecified | Treated as 1 by every renderer in practice |
| 1 | Do not dispose | Leave the frame in place; the next frame draws on top |
| 2 | Restore to background | Clear this frame's rectangle to transparent before the next |
| 3 | Restore to previous | Roll the canvas back to how it was before this frame |
Now the practical consequence: you cannot resize a frame in isolation. If a frame is a 40×30 patch at (120, 64) and you scale the canvas by half, the patch must land at (60, 32) and be 20×15 — and it must be composited against a correctly scaled version of everything underneath it. The only reliable approach is to expand every frame to a full canvas using the disposal rules, scale that, then re-encode. The process is called coalescing.
This is exactly why a resized GIF can end up larger than the original: coalescing turns a few small patches into full frames, and full frames cost full bytes. It is also why general image editors destroy animation — they do not implement any of this.
Timing, and the 100 ms lie
Each frame carries a delay in hundredths of a second, as a 16-bit field. In theory that gives you 10 ms resolution up to 655 seconds. In practice, browsers treat a delay of 0 or 1 as 10 — one tenth of a second.
The reason is historical: in the 1990s, a zero delay meant "play as fast as the machine can", and pages full of zero-delay GIFs pegged CPUs. Every browser clamped it, and every browser still does. The practical upshot is that GIF cannot reliably animate faster than about 10 fps, which is one more reason it is the wrong format for smooth motion.
GIF vs everything that came after
| GIF | APNG | Animated WebP | MP4 / WebM | |
|---|---|---|---|---|
| Colours | 256 | 24-bit | 24-bit | 24-bit |
| Alpha | 1-bit | 8-bit | 8-bit | none / 8-bit in WebM |
| Inter-frame compression | no | no | yes | yes |
| Relative size | 1× | 0.8–1.2× | 0.1–0.3× | 0.1–0.2× |
| Inline in email / README | yes | mostly | rarely | no |
GIF survives entirely because of the last row. Every technically superior format has some context — email clients, forum software, chat apps, documentation renderers — where it simply does not work, and GIF does. That is not a quality argument. It is an interoperability argument, and it is the only one GIF still wins.