An .lz4 file is one or more frames. This page follows the
LZ4 Frame Format
Description, version 1.6.5, in the lz4 repository (read 2026-11-13). Numbers are little-endian. The
compressed data inside each block is described on block
format.
Frame layout
| Field | Size | Description |
|---|---|---|
| Magic number | 4 | 184D2204, stored 04 22 4D 18. |
| FLG | 1 | See FLG. |
| BD | 1 | See BD. |
| Content size | 0 or 8 | With the content size flag: the size of the original data. Informational. |
| Dictionary ID | 0 or 4 | With the dictionary ID flag: which dictionary the compressor used. |
| Header checksum | 1 | (xxh32(descriptor, 0) >> 8) & FF: the second byte of the xxHash-32, seed 0, of the descriptor from FLG to the last optional field. |
| Data blocks | … | See data blocks. |
| End mark | 4 | 00000000. |
| Content checksum | 0 or 4 | With the content checksum flag: xxHash-32, seed 0, of all the original data. |
FLG byte
| Bits | Name | Meaning |
|---|---|---|
| 7 and 6 | Version | Must be 01. |
| 5 | B.Indep | 1: blocks are independent. 0: each block may refer to up to 64 KB of the blocks before it. |
| 4 | B.Checksum | Each block is followed by a checksum. |
| 3 | C.Size | The content size field is present. |
| 2 | C.Checksum | The content checksum is present. |
| 1 | Reserved | Must be 0. |
| 0 | DictID | The dictionary ID field is present. |
BD byte
| Bits | Meaning |
|---|---|
| 7 | Reserved, 0. |
| 6 to 4 | Block maximum size: 4 64 KB, 5 256 KB, 6 1 MB, 7 4 MB. 0 to 3 are not used. |
| 3 to 0 | Reserved, 0. |
The lz4 command-line tool’s defaults, in its lz4io.c
(read 2026-11-13), are block size ID 7 (4 MB), independent blocks, no block checksum, a content
checksum (“stream checksum” 1) and no content size, which make FLG 64 and BD 70.
Decoder rules from the specification: a decoder must be able to decode at least one working set of
parameters and may ignore checksums; whenever it does not support a parameter in the stream it must produce an
unambiguous error saying which. The version field must be 01, reserved bits must be 0, and a
frame with other values cannot be decoded by this version. The unused block size values 0 to 3 may be used in
a future revision, and a decoder conformant with this version only decodes the sizes defined here; it may
refuse block sizes above a system-specific limit. The frame header is 7 to 19 bytes with the magic (descriptor 3
to 15), the footer 4 to 8 bytes. Content size is informational (display or memory allocation): a decoder may skip it
or use it to validate the content. Several frames may be concatenated, each with its own flags; the specification
leaves decoding concatenated frames outside its scope (the reference lz4 tool decodes them in order).
Data blocks
| Field | Size | Description |
|---|---|---|
| Block size | 4 | Bit 31 set: the data is stored uncompressed. Bits 0 to 30: the size of the data, not counting a checksum. At most the block maximum size. |
| Data | … | LZ4 block format, or the bytes as they are. |
| Block checksum | 0 or 4 | With B.Checksum: xxHash-32, seed 0, of the stored data (before decoding), little-endian. Present even for empty blocks. It can be used together with the content checksum. |
00000000 is the end mark, not a block; 80000000 is a valid
empty stored block. Data that does not compress must be stored.
Linked blocks and dictionaries
Dependent blocks (the independence flag is 0) may reach back up to the LZ4 window, 64 KB, into earlier blocks, so the blocks must be decoded in order; this improves the ratio for small blocks but rules out random access and multi-threaded decoding.
A dictionary is a known prefix that the compressor may use. With independent blocks every block starts from the same dictionary; with linked blocks the dictionary is used only once, at the beginning of the frame. Compressor and decompressor must use exactly the same dictionary. The Dictionary ID field only helps the decoder choose it; only one Dict-ID may appear in a frame, the field is optional, and the dictionary can be known out of band.
xxHash-32
The header, block and content checksums use XXH32 with seed 0 (from the xxHash specification 0.2.0, read
2026-11-13). Everything is modulo 232, multi-byte reads are little-endian, <<< is
rotate left. Constants: P1 = 0x9E3779B1, P2 = 0x85EBCA77, P3 = 0xC2B2AE3D,
P4 = 0x27D4EB2F, P5 = 0x165667B1.
- Input of 16 bytes or more:
acc1 = seed + P1 + P2,acc2 = seed + P2,acc3 = seed,acc4 = seed − P1; for each 16-byte stripe of four 4-byte lanes, each accumulator takes its lane:acc = ((acc + lane × P2) <<< 13) × P1. Thenacc = (acc1 <<< 1) + (acc2 <<< 7) + (acc3 <<< 12) + (acc4 <<< 18). Shorter input:acc = seed + P5. - Add the input length (low 32 bits):
acc += length. - For each remaining 4 bytes:
acc = ((acc + lane × P3) <<< 17) × P4; for each remaining byte:acc = ((acc + byte × P5) <<< 11) × P1. - Avalanche:
acc ^= acc >> 15; acc *= P2; acc ^= acc >> 13; acc *= P3; acc ^= acc >> 16.
The digest is that 32-bit number; the canonical text form is big-endian, but LZ4 stores it little-endian. The
header checksum is (XXH32(descriptor) >> 8) & 0xFF.
Skippable frames
| Field | Size | Description |
|---|---|---|
| Magic number | 4 | Any of 184D2A50 to 184D2A5F. |
| Frame size | 4 | Size of the user data that follows. |
| User data | … | Ignored by decoders. |
A stream that must start with user data starts with an empty LZ4 frame, then the skippable frame. The same magic range is used by Zstandard.
Legacy frame
Written by early versions of the lz4 tool and still used by the Linux
kernel’s compressed images.
- Magic
184C2102, stored02 21 4C 18. - Then blocks, each a 4-byte compressed size and the compressed data. Every block is compressed, even when that makes it bigger, and every block but the last holds 8 MB of original data.
- No checksums. The frame ends at the end of the file or where another frame’s magic
number starts. The Linux kernel also accepts a zero size as an end mark, and so does
lz4since 1.11.0, but encoders should not write one.
Several frames
Frames are independent and each has its own settings. The specification does not
cover decoding several frames, but the lz4 tool decodes them all in
order, as one output.