How GIF Frame Delay Works in Graphic Control Extension

The Graphics Interchange Format (GIF) relies on the Graphic Control Extension block to govern how individual frames behave within an animated sequence. This article explains how the Graphic Control Extension defines the delay time between frames, detailing the specific byte structure used in the GIF89a specification, how delay intervals are measured, and how modern web browsers and decoders interpret edge cases like zero-delay values.

The Role of the Graphic Control Extension

In the GIF89a specification, animation is achieved by sequencing multiple images within a single data stream. The Graphic Control Extension (GCE) is an optional block that precedes a graphic rendering block—such as an Image Descriptor or Plain Text Extension—to define display parameters for that specific frame. It controls transparency, disposal methods, user input flags, and the duration the current frame must remain visible before advancing to the next.

Byte Structure of the Graphic Control Extension

A standard Graphic Control Extension consists of an eight-byte sequence:

  1. Extension Introducer (1 byte): Always 0x21, indicating the start of an extension block.
  2. Graphic Control Label (1 byte): Always 0xF9, identifying this block specifically as a Graphic Control Extension.
  3. Block Size (1 byte): Fixed value of 0x04, indicating that four bytes of data follow.
  4. Packed Fields (1 byte): Bit flags defining disposal methods, user input expectations, and transparency settings.
  5. Delay Time (2 bytes): An unsigned 16-bit integer defining frame duration.
  6. Transparent Color Index (1 byte): The color palette index used for transparency.
  7. Block Terminator (1 byte): Always 0x00, marking the end of the extension.

How Delay Time Is Measured

The delay time occupies bytes 5 and 6 of the GCE block. It is stored as a 16-bit unsigned integer using little-endian byte ordering, meaning the least significant byte appears first.

The value is measured in hundredths of a second (centiseconds), equivalent to increments of 10 milliseconds:

For example, to specify a delay of 250 milliseconds (25 centiseconds), the value 25 (0x0019 in hexadecimal) is encoded into the two delay bytes as 19 00.

Decoder Quirks and the Zero-Delay Problem

While the GIF89a specification allows a delay value of 0 (which implies the decoder should advance immediately or wait for user input), standard animated GIFs require continuous playback. Historically, decoding engines attempting to render a frame with a delay of 0 or 1 (10 milliseconds or less) would consume excessive CPU resources and cause severe frame-rate stuttering.

To maintain performance and visual consistency, modern web browsers and image decoders apply automatic clamping:

Consequently, animated GIFs designed to play at extremely high frame rates often run slower in web browsers than their raw byte values indicate.