GIF Format Explained — 256-Color Palettes and Animated Images
GIF explained: CompuServe's 1987 format, 87a and 89a, 256-color palettes, LZW, one-color transparency, animation, and when to use WebP or video.
GIF (Graphics Interchange Format) was released in 1987 by the US online service CompuServe, and the 1989 revision GIF89a added the extension blocks used for transparent colors and animation. It has been around since the early days of the internet and is still synonymous with short animated clips, but technically it's one of the oldest formats in use.
256-color palette and LZW compression
GIF doesn't store each pixel's color directly; instead it stores which entry of a palette of up to 256 colors (color table) the pixel uses. Per the specification, a color table can have a power-of-two size of up to 256 entries. This array of indices is losslessly compressed with the LZW algorithm.
The compression itself is lossless, but reducing a photo with more than 16 million colors to 256 colors causes major loss. Smooth gradients like skies and skin show up as dot patterns (dithering) or bands. On the other hand, pixel art and simple shapes with few colors are stored small and sharp.
The LZW algorithm once had patent issues, which were one of the reasons PNG was developed in the 1990s. Those patents have long since expired.
Transparency
GIF89a's Graphic Control Extension has a field for specifying one transparent color index. Pixels with that index aren't drawn, leaving the background visible. In other words, transparency is either "fully transparent or fully opaque", and semi-transparent shadows or soft edges can't be represented. That's why a transparent GIF placed on a different-colored background often shows a white fringe (halo) around its edges.
Animation
GIF animation displays multiple images in sequence, and the delay between frames is specified in units of 1/100 of a second by the specification. The loop count is set with an extension block (NETSCAPE2.0) that later became widely used.
File structure
A GIF file starts with a 6-byte signature, GIF87a or GIF89a, followed by these blocks:
- Logical Screen Descriptor: the width and height of the whole canvas and the background color index
- Global Color Table: a palette used throughout the file (optional)
- Graphic Control Extension: the next frame's delay, transparent color index and disposal method (89a)
- Image Descriptor and image data: the frame's position and size, a local color table if needed, and LZW-compressed data
- Steps 3–4 repeat for each frame, and a trailer byte (3B) comes last.
Since each frame can have its own local color table, a file can in theory use more than 256 colors overall, but the 256-color limit still applies within a single frame.
Strengths and limitations
- Compatibility: Every browser and messenger, and almost every program, plays it, animation included.
- Inefficient size: Each frame is compressed separately in 256 colors, so video-like content makes files very large. Google explains that animated WebP can deliver smaller sizes than GIF and APNG.
- Color and transparency limits: Only 256 colors and 1-bit transparency.
Main uses and alternatives
It's still used when playing everywhere matters most, such as short reaction images, loading icons and pixel art. For animated images on a website, animated WebP/AVIF or short videos (MP4, WebM) are much smaller and sharper.
Things to watch when converting
- GIF → JPG/PNG: Most tools save only the first frame as a still image.
- PNG/JPG → GIF: Colors are reduced to 256, so photos lose a lot of quality. Not recommended unless it's a logo or simple shape.
- For converting still images between formats, see the image converter.