An .lzma file is a 13-byte header followed by one LZMA stream. This page
follows
lzma-specification.txt
from Igor Pavlov’s LZMA SDK (a draft, read 2026-11-12 from a mirror of the SDK’s
DOC folder). Numbers are
little-endian. The compressed data is described on
LZMA coding.
Fields
| Offset | Size | Name | Description |
|---|---|---|---|
0 | 1 | Properties | (pb × 5 + lp) × 9 + lc; must be less than 225. See properties. |
1 | 4 | Dictionary size | In bytes. A decoder uses at least 4,096 (212) even if a smaller value is written. |
5 | 8 | Uncompressed size | Size of the decompressed data, or FF FF FF FF FF FF FF FF when unknown. |
13 | … | LZMA data | The range-coded stream. |
Properties
To unpack the byte d: lc = d % 9, d = d / 9,
lp = d % 5, pb = d / 5.
| Name | Range | Meaning |
|---|---|---|
lc | 0 to 8 | Literal context bits: how many high bits of the previous byte choose the model for the next literal. |
lp | 0 to 4 | Literal position bits: how many low bits of the position choose it too. |
pb | 0 to 4 | Position bits: how many low bits of the position choose the models for match and repeat decisions. |
The byte must be below 225 (9 × 5 × 5); a decoder rejects anything else. lc 3,
lp 0, pb 2 give 5D; the specification calls lc 3 and lp 0 the default
parameters. The format has no signature.
Where the data ends
- With a known size, the decoder stops after that many bytes. The stream may still end with an end marker, which is then optional.
- With an unknown size, the stream must end with the end marker: a match whose
distance decodes to
FFFFFFFF. - After the last bit the range decoder’s
Codemust be 0; the specification calls this check a very good way to detect corruption.
The format has no checksum, so damage may go unnoticed. The same five property bytes (properties and dictionary size) are used in 7z for the LZMA coder, without the size.
Example
5D properties: lc 3, lp 0, pb 2
00 00 80 00 dictionary 8 MiB (0x00800000)
FF FF FF FF FF FF FF FF uncompressed size unknown: an end marker follows the data
00 … LZMA data; the first byte of the range coder is always 00
Differences between programs
From the xz project’s lzma-file-format.txt (read 2026-11-13) and its test files.
- Properties: the format allows lc 0 to 8, lp 0 to 4 and pb 0 to 4. XZ Utils also requires lc + lp ≤ 4 and cannot read other files; LZMA Utils writes only lc 3, lp 0, pb 2.
- Dictionary size: any 32-bit value is possible, but for portability only 2n and 2n + 2n−1 are used. LZMA Utils writes 2n with 16 ≤ n ≤ 25. XZ Utils rounds up the value it stores.
- Uncompressed size: 264 − 1 means unknown (then the end marker is required). An end marker together with a known size is allowed but rare; XZ Utils 5.2.5 and older reject it. XZ Utils refuses a stated size of 256 GiB or more, which guards its guessing of whether a file is .lzma.
- Concatenation: two .lzma files joined are not one file. LZMA Utils and the LZMA SDK ignore everything after the first stream; XZ Utils reports data after it as corruption.
How damage shows
There is no checksum, so a decoder can only notice these (the xz test files bad-*.lzma are all of them):
- An unknown size and no end marker: the data simply ends (a truncated file).
- A stated size smaller than the data: after that many bytes the decoder expects an end marker or the end of the data, and finds a literal, a short rep or the middle of a match instead.
- A stated size larger than the data, with an end marker coming first.
- A range coder that does not start with a zero byte, or whose code register is not 0 at the end.