Introduction
GIF89a is the version of GIF that CompuServe published in 1989. Its specification gives the version dates as May 1987 for 87a and July 1989 for 89a, and the specification document itself is dated 31 July 1990. It keeps everything in GIF87a and adds extension blocks. The graphic control extension gives each frame a delay, a disposal method and a transparent colour, which is what makes animated and transparent GIFs possible. Comment, plain text and application extensions carry the rest.
Nearly every animated GIF on the web is a GIF89a file. A .gif file dropped
on any page of this site opens in the explorer, which shows the picture, plays any
animation, and lists every block and every LZW code byte by byte.
In this reference
- Header and screen – the signature, the logical screen and the global colour table
- Images – the image descriptor, local colour tables, sub-blocks and interlacing
- Extensions – graphic control, comment, plain text and application extensions
- LZW compression – the codes, the dictionary and how they are packed into bytes
- Animation – frames, delays, disposal methods, transparency and looping
Structure
A GIF starts with a 6-byte header, GIF89a, and a 7-byte logical screen
descriptor giving the canvas size (little-endian) and whether a global colour table
follows. The rest of the file is a series of blocks, each introduced by one byte:
21 for an extension, 2C for an image and 3B for
the trailer that ends the file.
An image block has a 10-byte descriptor, an optional local colour table, the LZW
minimum code size and the compressed data. Image data and extension data are written as
sub-blocks: a length byte of up to 255 followed by that many bytes, ending with a
zero-length sub-block. A graphic control extension before an image sets its delay and
transparent colour, and the NETSCAPE2.0 application extension sets the loop
count.
0HeaderGIF89a6 bytes6Logical screen descriptor width, height, flags, background colour7 bytes13Global colour table 3 bytes per colour, optional6 to 768 bytes…Frames repeated for each imagevaries21 F9Graphic control extension delay, transparency, disposal8 bytes2CImage descriptor position, size, flags10 bytes…Local colour table optional, then the LZW data sub-blocksvaries
…Trailer3B1 byte
Telling it apart
The file starts with GIF89a (47 49 46 38 39 61). A
GIF87a file differs only in those last three
characters, and has no extension blocks.
Not described
The GIF89a reference pages describe the whole file layout. The items below are unchecked, undefined by the specification or not yet written, and the viewer does not do everything; each reference page has its own “Not described” section with the detail.
Known, not yet covered
- Reference: application extensions other than NETSCAPE2.0, ICC and XMP that real files here carry (ImageMagick, ADOBE:IR1.0, MGKIPTC0000 and others); open source readers such as ImageMagick handle several. Would go on Extensions.
- Reference: which short delays browsers lengthen, and what Firefox does with the rest of the animation rules: browser source settles them, not checked yet (the NETSCAPE2.0 loop count was checked against Firefox’s source, 2026-11-18). Chrome, macOS’s ImageIO, Pillow and ffmpeg were checked (Animation).
- Reference: how the text of a plain text extension should be drawn: the GIF89a specification defines the grid but leaves the drawing open, and no real file has one, so it was checked on built files only.
- Viewer: plain text is listed with its grid, colours and text but not drawn; no decoder tried draws it.
- Viewer: ICC profiles (ISO 15076) and XMP packets are offered as files and not interpreted or applied.
- Viewer: the animation is played by the browser: the explorer does not run its own timing or apply the user input flag, both defined by the specification.
- Viewer: the pixel aspect ratio and the background colour are shown and not applied; the canvas starts transparent. Canvases over 16 million pixels are drawn with every nth pixel.
Unknown
- Reference and viewer: disposal methods 4 to 7: the specification says “to be defined”; described from built files only, as no real file uses 4 to 6. The viewer draws 4 as 3 and 5 to 7 as 0, as Chrome does (Animation).
- Reference and viewer: extension labels other than F9, FE, 01 and FF: none of the 32,958 real files has one. The viewer shows the sub-blocks as labelled bytes.
- Reference and viewer: a malformed XMP block (two real files): no source describes it. The viewer shows plain sub-blocks.
- Reference and viewer: damaged data, and a colour number past the end of a table: the specification is silent and decoders differ. The viewer leaves undecoded pixels transparent, with a note, and leaves the canvas unchanged for a colour number past the table.
- Viewer: a minimum 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 GIFs, including animations as layers (Windows, macOS, Linux)
- Adobe Photoshop – image editor that opens GIFs and exports them, with frames from its timeline (Windows, macOS)
- Photopea – image editor in the browser that opens and saves GIF (web browser)
- Ezgif – online tool for making, cutting and optimising animated GIFs (web browser)
- Gifsicle – command-line tool that edits and optimises GIF animations (Windows, macOS, Linux)
- ImageMagick – command-line tools that convert to and from GIF (Windows, macOS, Linux)
- IrfanView – image viewer that plays and converts GIFs (Windows)
- XnView MP – image viewer and batch converter (Windows, macOS, Linux)
Developers
Reference
- GIF89a specification – CompuServe’s revised specification, 1990