Introduction
GIF87a is the first version of GIF, published by CompuServe in 1987 so that pictures could be shared across the different computers that used its online service. A file holds a logical screen and one or more images placed on it, each with up to 256 colours from a palette and compressed without loss using LZW.
It has no transparency, no frame timing and no comments; those came with
GIF89a. Programs still write
GIF87a files when a picture needs none of the later additions.
Structure
The file starts with a 6-byte header, GIF87a, and a 7-byte logical
screen descriptor giving the canvas size (little-endian), the colour resolution and
whether a global colour table follows. Then come the images, each introduced by
2C, and the trailer 3B that ends the file.
Each image has a 10-byte descriptor giving its position and size on the screen, an optional local colour table, the LZW minimum code size and the compressed data in sub-blocks: a length byte of up to 255 followed by that many bytes, ending with a zero-length sub-block.
0HeaderGIF87a6 bytes6Logical screen descriptor width, height, flags, background colour7 bytes13Global colour table 3 bytes per colour, optional6 to 768 bytes…Images repeated for each imagevaries2CImage descriptor position, size, flags10 bytes…Local colour table optional, then the LZW data sub-blocksvaries
…Trailer3B1 byte
Extension blocks
GIF87a defines the form of an extension block and no extension. A block starts with
21 and a function code (0 to 255), then data blocks that end with a zero byte count.
An extension block may immediately precede any image descriptor or come before the
terminator, and the specification says CompuServe was to define and document each
extension itself.
A reader that does not know the function code reads past the blocks. A file marked
GIF87a that holds extensions from
GIF89a (graphic control, comment and so on) is
common; readers honour them, and the explorer reports it.
In this reference
- Header and screen – the signature, the screen descriptor and the global colour map
- Images – the image descriptor, local colour maps, raster data and interlacing
- LZW compression – the codes, the dictionary and how they are packed into bytes
Telling it apart
The file starts with GIF87a (47 49 46 38 37 61). A
GIF89a file starts with GIF89a
and may hold extension blocks, introduced by 21, between its images.
Not described
The GIF87a pages were checked against the GIF87a specification (15 June 1987) on 2026-11-18, and against real files; each reference page has its own “Not described” section with the detail. The interactive sequences of the specification’s Appendix B (escape sequences for a capabilities enquiry, a response such as #87a;1;0,320,200,4,0, and entering GIF mode) mediate between a host and a terminal and are not part of a file.
Known, not yet covered
- Reference: the LZW code size 1 case is described from decoders (the explorer, Chrome, ImageIO and ffmpeg agree), not from the specification; giflib’s source shows how it reads it.
- Viewer: extensions found in a file marked 87a are read and listed as for GIF89a, with a note; plain text is listed and not drawn (see GIF89a extensions).
- Viewer: the pixel aspect ratio and the background colour are shown and not applied; screens over 16 million pixels are drawn with every nth pixel.
Unknown
- Reference: how readers treat non-zero reserved header and flag bits: no source checked describes it.
- Reference and viewer: damaged data, an image past the screen and a colour number past the map: the specification is silent and decoders differ. The viewer leaves undecoded pixels transparent, with a note.
- Viewer: a code size above 8 gives no picture, and above 11 no code list (LZW compression).
Variants
- Graphics Interchange Format (GIF87a) – the first GIF: palette images on a logical screen, with no extensions
- Graphics Interchange Format (GIF89a) – the current GIF, with extensions for transparency, timing and animation
Links
Software
- GIMP – free image editor that opens, edits and saves GIF (Windows, macOS, Linux)
- Adobe Photoshop – image editor that opens and exports GIF (Windows, macOS)
- Photopea – image editor in the browser that opens and saves GIF (web browser)
- Gifsicle – command-line tool that edits and optimises GIF files (Windows, macOS, Linux)
- ImageMagick – command-line tools that convert to and from GIF (Windows, macOS, Linux)
- IrfanView – image viewer that opens and converts GIF (Windows)
- XnView MP – image viewer and batch converter (Windows, macOS, Linux)
Developers
Reference
- GIF87a specification – CompuServe’s original specification, 1987