An lzip file is one or more members one after another, with nothing between them. This page follows the “File format”, “Format of the LZMA stream in lzip files” and “Extra data appended to the file” chapters of the lzip manual (read 2026-11-13 from a web.archive.org copy, since the nongnu.org server did not answer). Numbers are little-endian.
Fields
| Offset | Size | Name | Description |
|---|---|---|---|
0 | 4 | ID string | 4C 5A 49 50, LZIP. |
4 | 1 | VN | Version, 1. Version 0 members also exist in old files; see version 0 members. |
5 | 1 | DS | Coded dictionary size. |
6 | … | LZMA stream | See stream. Ends with the end-of-stream marker. |
| end − 20 | 4 | CRC32 | CRC-32 of the original uncompressed data: the same CRC-32 as gzip and zlib (reflected polynomial 0xEDB88320, initial value 0xFFFFFFFF, final XOR 0xFFFFFFFF; details). |
| end − 16 | 8 | Data size | Size of the uncompressed data. |
| end − 8 | 8 | Member size | Size of the whole member, header and trailer included. |
Because each member ends with its own size, a tool can step backwards through a file from its end, member by member, and check every one against the data it holds.
Coded dictionary size
| Bits | Meaning |
|---|---|
| 0 to 4 | Base-2 logarithm of the base size, 12 to 29. |
| 5 to 7 | Numerator, 0 to 7, of a fraction of the base size, in sixteenths, to subtract from it. |
Dictionary size = 2bits 0–4 − (bits 5–7) × 2bits 0–4 / 16,
from 4 KiB to 512 MiB. Example: D3 is 219 − 6 × 215 =
512 KiB − 192 KiB = 320 KiB.
Stream
The data is an LZMA stream, coded as described on LZMA coding, with fixed parameters: lc 3, lp 0 and pb 2 (the manual calls it LZMA-302eos). Its first byte is always 0. It always ends with the end-of-stream marker: a match with distance 232 − 1 and length 2. The marker and the member size together let a decoder check that the stream is whole.
From the manual’s “Format of the LZMA stream in lzip files” chapter: lp is “optimized away”
and does not appear in the code. The first byte of the stream is zero so that tools such as
grep treat lzip files as binary. The end-of-stream marker is the only LZMA marker allowed. The
manual describes the stream by describing the decoder, with the source of lzd (an
educational decompressor, appendix A) as the reference. Coding sequences (bits MSB first):
| Bit sequence | Name | Meaning |
|---|---|---|
0 + byte | literal | one literal byte |
1 0 + len + dis | match | an LZ distance-length pair |
1 1 0 0 | shortrep | 1-byte match at the latest used distance |
1 1 0 1 + len | rep0 | len bytes at the latest used distance |
1 1 1 0 + len | rep1 | at the second latest used distance |
1 1 1 1 0 + len | rep2 | at the third latest used distance |
1 1 1 1 1 + len | rep3 | at the fourth latest used distance |
| Length code | Lengths |
|---|---|
0 + 3 bits | 2 to 9 |
1 0 + 3 bits | 10 to 17 |
1 1 + 8 bits | 18 to 273 |
Distances: a 6-bit “slot” (the position of the most significant set bit plus the next bit; 64
slots, 0 to 63) is context-coded. For a distance of 4 or more, direct_bits = (slot >> 1) − 1
(1 to 30) more bits follow. The slot alone gives distances 0 to 3; slot + direct_bits gives 4
to 127 (slots 4 to 13, the bits context-coded in reverse order, LSB first); for 128 to 232 − 1
(slot 14 and up) the first direct_bits − 4 bits are coded with fixed probability 0.5 and the last
4 bits are context-coded in reverse order.
Contexts hold the probability of a 0 bit. state is a 12-state machine (initial state 0);
pos_state the 2 low bits of the current position; literal_state the 3 high bits of
the last decoded byte; len_state the match length − 2 capped at 3. The states and the sequences
they remember (last is most recent): 0 literal, literal, literal; 1 match, literal, literal; 2 rep or (not
literal, shortrep), literal, literal; 3 literal, shortrep, literal, literal; 4 match, literal; 5 rep or (not
literal, shortrep), literal; 6 literal, shortrep, literal; 7 literal, match; 8 literal, rep; 9 literal,
shortrep; 10 not literal, match; 11 not literal, rep or shortrep.
| Context | Indexed by | Used for |
|---|---|---|
bm_match | state, pos_state | start of a sequence |
bm_rep | state | after sequence bit 1 |
bm_rep0 | state | after 11 |
bm_rep1 | state | after 111 |
bm_rep2 | state | after 1111 |
bm_len | state, pos_state | after 110 |
bm_dis_slot | len_state, bit tree | start of a distance |
bm_dis | reverse bit tree | after slots 4 to 13 |
bm_align | reverse bit tree | distances ≥ 128, after the fixed-probability bits |
There are two length context sets (Len_model), one for normal matches and one for repeated
matches: choice1 (length start), choice2 (after bit 1), bm_low (pos_state,
bit tree, after 0), bm_mid (pos_state, bit tree, after 10) and bm_high (bit tree,
after 11). bm_literal normally acts as a bit tree selected by literal_state; if the
previous decoded byte was not a literal, two other bit tree contexts are used, selected by each bit of
match_byte (the byte at the latest used distance), until a bit differs from the matching bit of
match_byte; the rest of the byte then uses the normal tree. The range decoder reads one byte at a
time (normalisation) and keeps two unsigned 32-bit variables, range starting at 232 − 1
and code at 0. After the header the decoder loops until the marker is decoded, then reads the
trailer and checks the CRC, the data size and the member size. The initial probabilities, shift constants,
bit-tree layouts and CRC table are not in the manual’s prose; they are in the source of lzd
(manual appendix A) and are given in the next section.
Constants and procedures
Read from the source of lzd, the educational decompressor in appendix A of the lzip manual
(manual version 1.26, 19 July 2026, web.archive.org copy fetched 2026-11-13; checked against the lzip 1.26 source, whose decoder is the same procedure). The values are those of the
LZMA decoder with lc 3, lp 0, pb 2.
| Constant | Value |
|---|---|
Probability width (bit_model_total_bits) | 11 bits: probabilities are integers below 2048 (bit_model_total) |
| Initial probability of every context | 1024 (bit_model_total / 2) |
Adaptation shift (bit_model_move_bits) | 5 |
| Range coder start | range = 0xFFFFFFFF; the first byte must be 0; the next four bytes, most significant first, make code |
| Normalisation | after each decoded bit, if range ≤ 0x00FFFFFF: range <<= 8 and code = (code << 8) | next byte |
| Context-coded bit | bound = (range >> 11) × probability. If code < bound: range = bound, probability += (2048 − probability) >> 5, bit 0. Otherwise code −= bound, range −= bound, probability −= probability >> 5, bit 1. |
| Direct (fixed 0.5) bit | range >>= 1; if code ≥ range: code −= range, bit 1, else bit 0; then normalise. |
pos_state_bits, literal_context_bits | 2 and 3 (literal_pos_state_bits is 0 and does not appear) |
| Minimum match length | 2 |
| Dictionary size limits | 4096 (212) to 229 bytes |
| CRC-32 | table of 256 entries: for n = 0 to 255, take c = n and 8 times: if the low bit is set, c = 0xEDB88320 XOR (c >> 1), else c >>= 1. The register starts at 0xFFFFFFFF; for each data byte, register = table[(register XOR byte) & 0xFF] XOR (register >> 8); the stored value is the register XOR 0xFFFFFFFF, little endian. |
Context arrays and bit trees
A bit tree of n bits uses contexts numbered from 1: start with symbol = 1 and
n times set symbol = (symbol << 1) | the bit decoded with context
symbol; the result is symbol − 2n. A reversed bit tree decodes the same way and
then reverses the order of the n bits of the result. Sizes (all start at probability 1024):
| Array | Dimensions | Use |
|---|---|---|
bm_literal | 8 × 0x300 | row chosen by literal_state = previous byte >> 5 (0 for the first byte of the member); a normal literal is an 8-bit tree on the row |
bm_match | 12 × 4 | [state][pos_state] |
bm_rep, bm_rep0, bm_rep1, bm_rep2 | 12 each | [state] |
bm_len | 12 × 4 | [state][pos_state], the shortrep bit |
bm_dis_slot | 4 × 64 | 6-bit tree on row len_state |
bm_dis | 115 (128 − 14 + 1) | reversed trees for slots 4 to 13; for a slot, the tree starts at index (base distance − slot), where base distance = (2 | (slot & 1)) << direct_bits |
bm_align | 16 | 4-bit reversed tree |
| Length model (two copies: match and rep) | choice1, choice2; bm_low 4 × 8; bm_mid 4 × 8; bm_high 256 | choice1 = 0: 3-bit tree on bm_low[pos_state], length 2 + value. Else choice2 = 0: 3-bit tree on bm_mid[pos_state], length 10 + value. Else 8-bit tree on bm_high, length 18 + value. |
Procedures
- State machine (initial 0;
state< 7 means the last sequence was a literal): after a literal, state = {0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 4, 5}[state]; after a match, 7 if state < 7 else 10; after a rep, 8 if state < 7 else 11; after a shortrep, 9 if state < 7 else 11. - Literal after a match (state ≥ 7):
match_byteis the byte at distance rep0 + 1. For each bit from the top, withsymbolstarting at 1, the context isbm_literal[row][symbol + (match_bit << 8) + 0x100]. At the first bit that differs from the match bit, the remaining bits use the ordinary contextsrow[symbol]untilsymbolreaches 0x100. - Sequence selection:
pos_state= position in the member’s data & 3.bm_matchbit 0: literal. Elsebm_repbit 0: match: the distances shift (rep3 = rep2, rep2 = rep1, rep1 = rep0), the length comes from the match length model,len_state= min(length − 2, 3), and the slot frombm_dis_slot[len_state]. Elsebm_rep0bit 0: thenbm_lenbit 0 is a shortrep (one byte at rep0), bit 1 is rep0 with a rep length;bm_rep0bit 1:bm_rep1bit 0 selects rep1, elsebm_rep2bit 0 selects rep2, 1 selects rep3, and the chosen distance moves to the front. - Distance from a slot: slot < 4 is the distance itself. Otherwise
direct_bits= (slot >> 1) − 1 and distance = (2 | (slot & 1)) <<direct_bits, plus for slots below 14 the reversed tree ofdirect_bitsbits inbm_dis, and for slot 14 and up thedirect_bits− 4 direct bits shifted left by 4, plus the 4-bit reversed tree inbm_align. A distance value of0xFFFFFFFFis the marker: with length 2 it is the end-of-stream marker; any other length is an error. The distance stored is the real distance minus 1. - First sequence (manual 1.26): the four latest distances start at 0, and the state starts as if the byte before the first output byte were a 0 decoded as a literal. The first sequence can be anything except a match. A first shortrep puts one byte with value 0 in the output; a first repN puts
lengthbytes with value 0. Distances run from 0 to the dictionary size − 1. A distance that points before the start of the output is the only decoding error malformed LZMA input can cause, so a stream with no match whose distance is out of bounds is valid. - Invalid match: a distance (minus 1) at or above the dictionary size, or at or beyond the data decoded so far in the first dictionary-size bytes, is an error.
Version 0 members
Files written by lzip before version 1 of the format have VN = 0. The header is the same 6 bytes and the
dictionary size is coded the same way; the difference is the trailer, which has 12 bytes, not 20: the CRC-32
and the data size, with no member size field. Read from lzip 1.16’s lzip.h (the trailer size is
12 when the version is below 1, 20 otherwise; the header check accepts versions up to 1) and its
decoder.cc, which for a version 0 member takes the member size as the position reached plus the
trailer size instead of reading it. So a version 0 member lacks the member-size check and the backwards
indexing that depends on it. The current manual (1.26) and its reference decoder lzd describe and accept
only version 1; which lzip release dropped version 0 could not be checked against lzip’s own source or ChangeLog (not
readable here), so it is not stated. The same 1.16 decoder also accepted a Sync Flush marker (distance
0xFFFFFFFF with length 3) in the stream, after which it restarts the range decoder (it reloads
the five initial bytes); the lzip 1.26 manual and its reference decoder lzd allow only the end-of-stream marker. In the 1.16 sources (read
2026-11-14 through lzlib’s decoder.c, which shares the code) the marker is told from the end-of-stream
marker by its length: after a match of distance 0xFFFFFFFF, length 2 is the end-of-stream marker and
length 3 (min_match_len + 1) is the Sync Flush marker, after which the decoder reloads the range coder
(the first byte must be 0) and carries on with the same dictionary, state and probabilities. lzlib’s own
documentation says the marker is “not allowed in lzip files; it is a device for interactive communication”. The viewer
follows the marker in any member, names it in the Symbols table, and notes that a version 1 member should not hold one.
Multimember files and limits
- A multimember file has no size limit. Each member holds up to 16 EiB − 1 bytes of data, and a member is at most 2 PiB.
- Empty members (data size 0) are not allowed in a multimember file.
- Data after the last member is not part of the format and is normally ignored.
Zero bytes can be added safely; so can text, if its first four bytes differ from
LZIPin each position (none of the first four bytes of the text may match the corresponding byte ofLZIP) and it has no zero bytes. Zero bytes and nonzero bytes cannot be safely mixed in trailing data, unless the trailing data are appended with the--appendoption of lziprecover. The manual lists what trailing data can be: padding (for example to a block size when writing to tape), data added by the user (a recovery record, an “End Of File” string, a hash, a description), garbage from a failed copy, malicious data meant to make a file’s size and hash match another’s, or, rarely, the corrupt header of another member. Tools are expected to behave usefully when they are present, normally ignoring them. lzip’s test that tells trailing data from a corrupt header has a Hamming distance of 3 (three bit flips in different magic bytes are needed to fool it), and its--trailing-erroroption makes a file with trailing data an error. - The header has a fixed length of 6 bytes and the LZMA stream always starts at offset 6. The maximum dictionary size of 512 MiB is chosen so that any lzip file can be decompressed on a 32-bit machine. The member size is a distributed index: it lets a reader list members, check stream integrity and recover undamaged members. The CRC, the data size and the member size give, with the end-of-stream marker, “3-factor” integrity checking, and a decoder reports a mismatch in each separately.
Example
4C 5A 49 50 "LZIP"
01 version 1
0C DS: 2^12 = 4 KiB dictionary
00 … LZMA stream, ending with the end-of-stream marker
xx xx xx xx CRC32 of the data
05 00 00 00 00 00 00 00 data size 5
xx xx xx xx xx xx xx xx member size