How GIFs actually work

Palettes, LZW, disposal methods, and the reasons your resized GIF came out bigger.

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.

ValueNameBehaviour
0UnspecifiedTreated as 1 by every renderer in practice
1Do not disposeLeave the frame in place; the next frame draws on top
2Restore to backgroundClear this frame's rectangle to transparent before the next
3Restore to previousRoll 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

GIFAPNGAnimated WebPMP4 / WebM
Colours25624-bit24-bit24-bit
Alpha1-bit8-bit8-bitnone / 8-bit in WebM
Inter-frame compressionnonoyesyes
Relative size1×0.8–1.2×0.1–0.3×0.1–0.2×
Inline in email / READMEyesmostlyrarelyno

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.

Questions people actually ask

Is GIF lossless?

The LZW compression is lossless, but the format is not: reducing an image to 256 colours per frame is irreversible. A GIF of a photograph has permanently discarded most of its colour information before compression even starts.

Why does my GIF only show the first frame in an editor?

Because most image editors treat a GIF as a single image. The first frame is a valid standalone image, so that is what you get. Editing animation frame-by-frame needs a tool that understands the frame stack and disposal methods.

Why can't a GIF have smooth transparency?

GIF predates alpha channels. Its transparency is a single reserved palette index: a pixel either uses that index (and is invisible) or it does not. There is no way to express 50% opacity. Animated WebP and APNG both support 8-bit alpha.

Why is my GIF stuck at 10 fps even though I set 30?

Because a delay under 2 hundredths of a second gets clamped to 10 by browsers, so the practical maximum is about 10 frames per second. Below 100 ms per frame, the timing you wrote is not the timing that plays.

Does GIF support audio?

No. There is no audio track in the format and no way to add one. If you need sound, you need video — which is also 5–10× smaller.