What empty sub-block size ends a GIF sub-block series?

The story behind the answer

An empty sub-block of 0 bytes ends a GIF sub-block series. Each sub-block begins with a length byte, followed by that many data bytes; a length of zero signals that no more data follows.

GIF uses this structure for image data and extension data, allowing a decoder to skip through a block even when it does not understand every feature. Ordinary sub-blocks can contain from 1 through 255 data bytes, so 255 bytes is the largest regular sub-block, not the terminator.

The zero-length terminator is separate from the GIF file trailer. After the relevant data and extensions have ended, a GIF normally finishes with a trailer byte valued 0x3B. Confusing the terminator with the trailer is a common mistake: the zero byte ends one sub-block chain, while 0x3B marks the end of the file.

The same basic sub-block convention appears in several GIF structures, including LZW-compressed image data, comments, and application extensions.

Source: Wikipedia · fact-checked Sept. 2026

Add question to a list

Choose a list to keep this question in: