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:
- Extension Introducer (1 byte): Always
0x21, indicating the start of an extension block. - Graphic Control Label (1 byte): Always
0xF9, identifying this block specifically as a Graphic Control Extension. - Block Size (1 byte): Fixed value of
0x04, indicating that four bytes of data follow. - Packed Fields (1 byte): Bit flags defining disposal methods, user input expectations, and transparency settings.
- Delay Time (2 bytes): An unsigned 16-bit integer defining frame duration.
- Transparent Color Index (1 byte): The color palette index used for transparency.
- 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:
- A delay value of
10represents 10/100 of a second, or 100 milliseconds (yielding roughly 10 frames per second). - A delay value of
100represents 100/100 of a second, or exactly 1.0 second. - Because the field is 16 bits wide, the theoretical maximum delay for a single frame is 65,535 hundredths of a second, or roughly 655.35 seconds (nearly 11 minutes).
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:
- Delays of
0or values below a minimum threshold (typically anything less than2, or 20 milliseconds) are automatically overridden. - Most rendering engines substitute these ultra-low values with a safe default, commonly 10 centiseconds (100 milliseconds).
Consequently, animated GIFs designed to play at extremely high frame rates often run slower in web browsers than their raw byte values indicate.