A compressed LZ4 block is a series of sequences. Each sequence copies some literal bytes, then copies a match from data already decoded. There is no entropy coding. This page follows the LZ4 Block Format Description in the lz4 repository (revised 2026-10-26), read 2026-11-12. The format sets no size limit on lengths or blocks.
Sequence
| Field | Size | Description |
|---|---|---|
| Token | 1 | High 4 bits: literal length, 0 to 15. Low 4 bits: match length − 4, 0 to 15. |
| Literal length bytes | 0 or more | Only when the high nibble is 15: add bytes to the length until one is less than 255 (each FF adds 255 and continues). |
| Literals | literal length | Copied to the output as they are. |
| Offset | 2 | Little-endian, 1 to 65,535: how far back the match starts. 0 is invalid. |
| Match length bytes | 0 or more | Only when the low nibble is 15: as for literals. The match length is the total + 4 (the minimum match). |
A match may overlap the bytes it is producing (offset smaller than its length),
which repeats a pattern: offset 1 and length 10 writes the last byte ten more times.
Example: literal length 18 is a high nibble of 15 and one extra byte 03;
280 would be 15, FF, 0A.
End of a block
- The last sequence has only literals: it ends after them, with no offset or match. The low 4 bits of its token are unused; encoders should write 0 and decoders ignore them.
- The last 5 bytes of input are always literals. Input shorter than 5 bytes is one sequence of literals; even empty input is a single zero byte.
- The last match must start at least 12 bytes before the end of the block. So blocks under 12 bytes cannot be compressed, and independent blocks under 13 bytes cannot either, since they must start with at least one literal.
A conformant decoder may reject a block that breaks these rules; they exist for compatibility with historical decoders that rely on them for speed. The document recommends that decoders check every length and offset against their buffers, detect length overflows, and accept lengths and blocks up to 4 MB.
Linked blocks and dictionaries
When a frame has dependent blocks, an offset may reach back into the previous 64 KB of decoded data from earlier blocks. A dictionary acts as data decoded before the first block.