Each block is a block header, the compressed data, 0 to 3 zero bytes of block padding to a multiple of 4, and the check named in the stream flags. Blocks are independent, so they can be compressed and decompressed in parallel. Variable-length integers are described on the stream page.
Block header
| Field | Size | Description |
|---|---|---|
| Block header size | 1 | 01 to FF; the header is (value + 1) × 4 bytes, 8 to 1,024. A 00 here is the index indicator instead. |
| Block flags | 1 | Bits 0 and 1: number of filters − 1 (1 to 4 filters). Bits 2 to 5: reserved, 0. Bit 6 (40): compressed size present. Bit 7 (80): uncompressed size present. |
| Compressed size | varint | Only with bit 6: size of the compressed data, without padding or check. Not 0. |
| Uncompressed size | varint | Only with bit 7. |
| Filter flags | repeated | For each filter, in order of encoding: filter ID (varint), size of properties (varint), properties. |
| Header padding | … | Zero bytes up to the header size less 4. |
| CRC32 | 4 | CRC-32 of the header up to here. |
A typical header from xz is 02 00 21 01 16 00 00 00 and a
CRC: size byte 2 (12 bytes), flags 0 (one filter, no sizes), filter
21 (LZMA2) with 1 byte of properties, 16 (an 8 MiB
dictionary), then padding.
Filter IDs
| ID | Filter | Properties | Where |
|---|---|---|---|
21 | LZMA2 | 1 byte: dictionary size | Last only |
03 | Delta | 1 byte: distance − 1 (1 to 256) | Not last |
04 | x86 (BCJ) | 0 or 4 bytes: start offset | Not last |
05 | PowerPC, big-endian | 0 or 4 bytes | Not last |
06 | IA-64 (Itanium) | 0 or 4 bytes | Not last |
07 | ARM, little-endian instructions | 0 or 4 bytes | Not last |
08 | ARM Thumb | 0 or 4 bytes | Not last |
09 | SPARC | 0 or 4 bytes | Not last |
0A | ARM64 | 0 or 4 bytes | Not last |
0B | RISC-V | 0 or 4 bytes | Not last |
Plain LZMA (the .lzma method) is not allowed; only LZMA2. The branch filters convert relative jump and call addresses in machine code to absolute ones so that they compress better; the optional 4-byte start offset (little-endian) must be a multiple of the filter’s alignment: x86 1, PowerPC 4, IA-64 16, ARM 4, ARM Thumb 2, SPARC 4, ARM64 4 (4,096 works best), RISC-V 2. Delta subtracts the byte distance bytes earlier, for samples and tables.
Filter chain rules
- At most four filters, so at most three that are not last.
- At most two of the non-last filters may change the size of the data, and they must not expand it much (about 2n bytes in must give at least n out).
- The last filter’s output is aligned to 4 bytes from the start of the stream.
Custom filter IDs
A developer can ask the maintainer for an ID range, or make one: bits 0 to 15 the
filter, bits 16 to 55 a random 40-bit developer ID, bits 56 to 62 the prefix
3F, which always encodes in 9 bytes. IDs of 262 and above are
for internal use and never appear in files. The ranges 300 to
4FF, 20000 to 7FFFF and 2000000 to
7FFFFFF are reserved because 7z uses those method IDs.
LZMA2 properties
One byte. Bits 0 to 5 encode the dictionary size; bits 6 and 7 are reserved, 0.
For values 0 to 39 the size is (2 | (b & 1)) << (b / 2 + 11):
0 is 4 KiB, 1 is 6 KiB, 2 is 8 KiB, and so on up to 39, 3 GiB. 40 means
4 GiB − 1. Above 40 is an error. For example, 16 (22) is 8 MiB.
LZMA2 chunks
The xz specification gives
only the filter ID and the property byte above; the chunks below follow the LZMA
SDK’s decoder, C/Lzma2Dec.c,
whose header comment lays them out. Both were read 2026-11-12. LZMA2 data is a
series of chunks, each starting with a control byte.
| Control | Chunk |
|---|---|
00 | End of the LZMA2 data. |
01 | Uncompressed chunk, and reset the dictionary; the next LZMA chunk must then reset the state and set new properties. Then 2 bytes, big-endian: size − 1 (up to 64 KiB). Then the bytes. |
02 | Uncompressed chunk, no reset. |
03 to 7F | Invalid. |
80 to FF | LZMA chunk. Bits 0 to 4 are bits 16 to 20 of (uncompressed size − 1); then 2 bytes big-endian complete it (up to 2 MiB). Then 2 bytes big-endian: compressed size − 1 (up to 64 KiB). Then, for resets 2 and 3, a properties byte (pb × 5 + lp) × 9 + lc with lc + lp ≤ 4. Then the LZMA data. |
Bits 5 and 6 of an LZMA chunk’s control byte say what to reset first:
| Value | Reset |
|---|---|
0 (80) | Nothing: continue the previous chunk’s state. |
1 (A0) | The LZMA state. |
2 (C0) | The state, with new properties. |
3 (E0) | The state, new properties and the dictionary. The first chunk must reset the dictionary. |
Every chunk header gives its packed size, so chunks can be stepped over without decoding them.
Rules a decoder enforces
Checked against liblzma and the xz project’s test files (bad-1-lzma2-1 to -11):
- The first chunk of a block must reset the dictionary (control
01orE0and above). - After a dictionary reset, the next LZMA chunk must set new properties (
C0and above). An LZMA chunk before any properties is an error. - Control bytes
03to7Fare errors. lc + lp above 4 is an error, and so is a properties byte of 225 or more. - An LZMA chunk starts a new range coder (a zero byte and four bytes of code) and must use exactly its compressed size; the code register must end at 0. An end-of-payload marker inside a chunk is an error.
- A match may not reach back before the last dictionary reset. An uncompressed chunk changes neither the state nor the properties, but its bytes are part of the dictionary.
- The stream must end with the
00control byte, and the sizes in the block header and the index must equal what the chunks add up to.
Example
The block of the xz test file good-1-lzma2-4.xz (464 bytes, CRC64). It starts at byte 12.
02 00 21 01 08 00 00 00 D8 0F 23 13 block header: 12 bytes, one filter, LZMA2, dictionary 64 KiB, CRC32
E0 00 BB 00 A1 5D | 00 26 1B CA … chunk 1: LZMA, reset everything; 188 bytes from 162; lc 3 lp 0 pb 2; range coder starts 00
01 00 26 | 6C 61 62 6F 72 … chunk 2 (at 0xC0): stored, resets the dictionary; 39 bytes "labor…"
C0 00 E5 00 BD 5D | 00 31 9B CA … chunk 3 (at 0xEA): LZMA, state and new properties; 230 bytes from 190
00 the end marker (at 0x1AE), then 1 byte of padding and the 8-byte CRC64
Chunk 1: the control byte E0 is 1110 0000, an LZMA chunk with reset level 3 and the high bits of the
size 0; 00 BB is 187, so 188 bytes; 00 A1 is 161, so 162 compressed bytes; 5D
is lc 3, lp 0, pb 2. Chunk 3 has no dictionary reset, so its matches can reach back into chunks 1 and 2.