How many bytes can a GIF data sub-block contain at most?

The story behind the answer

A GIF data sub-block can contain at most 255 bytes.

Each GIF data sub-block begins with a single size byte that states how many data bytes follow. That count can range from 1 through 255, so 255 bytes is the maximum payload of one sub-block. A zero-length sub-block, represented by a size byte of 0, terminates the sequence; it is not a data sub-block carrying content.

This arrangement lets GIF store variable-length image or extension data while keeping the parser simple. LZW-compressed image data is commonly split across a chain of sub-blocks, and extension data uses the same general mechanism. The size byte comes before every chunk, allowing a decoder to skip or read each section without knowing the entire file’s length in advance.

The limit applies to each sub-block, not to the whole image or GIF file. A large image may therefore contain many 255-byte chunks, followed by a zero-byte terminator. Another common mistake is choosing 256 because a byte can represent 256 values; the value 0 is reserved here for termination, leaving 1–255 for actual sub-block lengths.

Source: Wikipedia · fact-checked Sept. 2026

Add question to a list

Choose a list to keep this question in: