A GIF87a file starts with a 6-byte signature and a 7-byte screen descriptor, followed at once by the global colour map when there is one. Numbers of more than one byte are little-endian, low byte first. The logical screen can be larger than the physical display; what happens then is up to the program (scrolling, or clipping at the edges). The pixel value (bits 2–0 of the flags) also gives the largest number of colours in an image, 2 to 256.
Signature
| Offset | Size | Type | Name | Description |
|---|---|---|---|---|
| 0 | 3 | ASCII | signature | GIF. |
| 3 | 3 | ASCII | version | 87a. |
Screen descriptor
| Offset | Size | Type | Name | Description |
|---|---|---|---|---|
| 6 | 2 | u16 | width | The width of the screen in pixels. |
| 8 | 2 | u16 | height | The height of the screen in pixels. |
| 10 | 1 | u8 | flags | Colour map flag, colour resolution and bits per pixel. |
| 11 | 1 | u8 | background | The colour index of the screen’s background. |
| 12 | 1 | u8 | reserved | Zero. GIF89a later used this byte for the pixel aspect ratio. |
Flags
| Bits | Name | Meaning |
|---|---|---|
| 7 | global colour map | 1 if a global colour map follows the descriptor. |
| 6–4 | colour resolution | Bits of colour resolution, minus 1. |
| 3 | reserved | Zero. GIF89a later used it as the sort flag. |
| 2–0 | pixel | Bits per pixel, minus 1: 0 to 7, for 2 to 256 colours. |
Global colour map
Straight after the descriptor when bit 7 of the flags is set: 2pixel + 1
entries of three bytes each, red, green and blue. A pixel value is an index into it.
The map is optional but recommended where accurate colour matters. Each component is a
fraction of full intensity from 0 to 255: white is (255, 255, 255), black (0, 0, 0). A
display that has fewer than 8 bits for a component uses the high-order bits, and a
writer on such hardware scales its values with
value × 255 ÷ (2bits − 1). With no global map the decoder makes
a default one, mapping each colour index to the same hardware colour index modulo the
number of colours the hardware has.
| Offset | Size | Type | Name | Description |
|---|---|---|---|---|
| 0 | 1 | u8 | red | Colour 0, red, 0 to 255. |
| 1 | 1 | u8 | green | Colour 0, green, 0 to 255. |
| 2 | 1 | u8 | blue | Colour 0, blue, 0 to 255. |
Not described
What this page leaves out, and what the explorer does not do with the header and screen.
Known, not yet covered
- Reference: none left from the 87a text: this page was checked line by line against the GIF87a specification (spec-gif87.txt, 15 June 1987) on 2026-11-18 and against 6,804 real GIF87a files. The interactive sequences of its Appendix B (capabilities enquiry and response, entering GIF mode) are not part of a file.
- Viewer: the pixel aspect ratio and the sort flag are shown as for GIF89a and not applied; the background colour is shown and not painted.
Unknown
- Reference: how readers treat a GIF87a file whose last header byte, or bit 3 of the flags, is not zero: no source checked describes it.
- Viewer: a global colour map cut short by the end of the file is shown as far as it goes, with a note.