Each member names its own method in a two-byte field in its local and central headers, so one archive can mix methods. In practice almost all members are stored or Deflate.
Method numbers
| Number | Method |
|---|---|
0 | Stored (no compression) |
1 | Shrink |
2 to 5 | Reduce, factors 1 to 4 |
6 | Implode |
7 | Reserved for a tokenizing algorithm, not used by PKZIP |
8 | Deflate |
9 | Enhanced Deflate (Deflate64) |
10 | PKWARE Data Compression Library Imploding (old IBM TERSE) |
11 | Reserved by PKWARE |
12 | bzip2 |
13 | Reserved by PKWARE |
14 | LZMA |
15 | Reserved by PKWARE |
16 | IBM z/OS CMPSC |
17 | Reserved by PKWARE |
18 | IBM TERSE (new) |
19 | IBM LZ77 z Architecture |
20 | Deprecated: use 93 for Zstandard |
93 | Zstandard |
94 | MP3 |
95 | XZ |
96 | JPEG variant |
97 | WavPack |
98 | PPMd version I, revision 1 |
99 | AE-x encryption marker, not a method: the real method is in the 0x9901 extra field |
APPNOTE says methods 1 to 6 are legacy and should not be used to compress new files. A method’s minimum version is in the version table.
The explorer decompresses stored, Shrink, Reduce, Implode, Deflate, Deflate64, DCL Implode, bzip2, LZMA, CMPSC, WavPack, PPMd, Zstandard and XZ members, and checks each against the CRC-32. It names the rest and shows why they are not decoded: 18, 19, 94 and 96, for which no public specification was found (searches for IBM’s methods 18 and 19 and for WinZip’s 94 and 96 turned up none; that is not proof that none exists). Numbers 7, 11, 13, 15 and 17 are reserved, and numbers APPNOTE does not assign (21 to 92, and 100 up) are not used; a member with any of these is reported.
What the sizes count
The compressed size is the whole of what is stored for the member. It includes the method’s own header, any end marker, and the encryption header or trailer. A member’s stored bytes start immediately after its local header, with no alignment other than padding in its extra field. The CRC-32 and uncompressed size are of the original data.
Stored (method 0)
The file’s bytes, unchanged. The compressed and uncompressed sizes are equal, unless the member is encrypted.
Deflate (method 8)
Raw Deflate as defined in RFC 1951, with no zlib header or trailer. The bit stream reads the low bits of each byte first. It is a series of blocks, each starting with three bits.
| Bits | Meaning |
|---|---|
| 1 | BFINAL: 1 if this is the last block. |
| 2 | BTYPE: 00 stored, 01 fixed Huffman, 10 dynamic Huffman, 11 an error. |
A stored block skips to the next byte boundary, then has a 16-bit length and its one’s complement, then that many literal bytes. Huffman blocks hold literals and length and distance pairs, ending with code 256. The window is 32 KiB. Since the stream ends at its last block, a reader knows where a Deflate member ends without the sizes.
Fixed Huffman code
| Literal values | Code length in bits |
|---|---|
| 0 to 143 | 8 |
| 144 to 255 | 9 |
| 256 to 279 | 7 |
| 280 to 287 | 8 |
Distance codes 0 to 31 are all 5 bits. Literal codes 286 and 287 and distance codes 30 and 31 are never used.
Dynamic Huffman header
| Bits | Meaning |
|---|---|
| 5 | HLIT: number of literal and length codes minus 257 (257 to 286). The value 0 means 257. |
| 5 | HDIST: number of distance codes minus 1 (1 to 32). |
| 4 | HCLEN: number of code length codes minus 4 (4 to 19). |
These counts are as RFC 1951 gives them (section 3.2.7). APPNOTE 5.5.3 words the same fields differently: “# of Literal codes sent − 256 (256 – 286)” and “# of Bit Length codes − 3 (3 – 19)”, with distance codes as − 1 (1 – 32). RFC 1951 is the specification of Deflate itself, and this page follows it; APPNOTE’s text differs from the RFC for the first and third.
Then the code length codes, 3 bits each, in the order 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15. These encode the literal and distance code lengths, using 16 for “repeat the previous length 3 to 6 times” (2 extra bits), 17 for a run of 3 to 10 zeros (3 extra bits) and 18 for a run of 11 to 138 zeros (7 extra bits). Codes are assigned from the shortest length up, all zeros first.
Length and distance codes
| Length codes | Extra bits | Lengths |
|---|---|---|
| 257 to 264 | 0 | 3 to 10 |
| 265 to 268 | 1 | 11 to 18 |
| 269 to 272 | 2 | 19 to 34 |
| 273 to 276 | 3 | 35 to 66 |
| 277 to 280 | 4 | 67 to 130 |
| 281 to 284 | 5 | 131 to 257 |
| 285 | 0 | 258 |
| Distance codes | Extra bits | Distances |
|---|---|---|
| 0 to 3 | 0 | 1 to 4 |
| 4 to 5 | 1 | 5 to 8 |
| 6 to 7 | 2 | 9 to 16 |
| 8 to 9 | 3 | 17 to 32 |
| 10 to 11 | 4 | 33 to 64 |
| 12 to 13 | 5 | 65 to 128 |
| 14 to 15 | 6 | 129 to 256 |
| 16 to 17 | 7 | 257 to 512 |
| 18 to 19 | 8 | 513 to 1,024 |
| 20 to 21 | 9 | 1,025 to 2,048 |
| 22 to 23 | 10 | 2,049 to 4,096 |
| 24 to 25 | 11 | 4,097 to 8,192 |
| 26 to 27 | 12 | 8,193 to 16,384 |
| 28 to 29 | 13 | 16,385 to 32,768 |
APPNOTE says flag bits 1 and 2 record the compression level the writer used.
Deflate64 (method 9)
Deflate with a 64 KiB window. It differs from method 8 in the decoding tables only:
- Length code 285 has 16 extra bits and a base of 3, giving lengths 3 to 65,538, instead of the single value 258.
- Distance codes 30 and 31 become valid, with 14 extra bits each and bases of 32,769 and 49,153, giving distances up to 65,536.
APPNOTE does not give the tables. These values are from zlib’s
contrib/infback9. Version needed is 2.1.
Shrink (method 1)
Dynamic LZW with partial clearing. Codes start at 9 bits and can grow to 13. The code 256 introduces control sequences:
256, 1: the code size grows by one. The next code is read at the new size, with no alignment.256, 2: partial clear. Leaf nodes are removed from the table, the code size stays as it is, and freed codes are used again from the lowest up. The compressor can send this at any time.
Reduce (methods 2 to 5)
Two stages: repeated-byte compression, then probabilistic coding of the result. The four methods differ only in compression factor, 1 to 4.
The data starts with 256 follower sets, S(255) first and S(0) last. Each is a 6-bit count N, 0 to 32, followed by N 8-bit values. Then the coded bytes follow. Last-Character starts at 0. For each byte:
- If the set for Last-Character is empty, read 8 bits as a literal.
- Otherwise read 1 bit. A 1 means an 8-bit literal follows. A 0 means read B(N) bits as an index and output that element of S(Last-Character), where B(N) is the minimum number of bits to encode N − 1.
The output of that stage is fed to a small state machine that expands repeated bytes.
The byte 144 is DLE:
| State | Input | Action |
|---|---|---|
| 0 | Any byte other than 144 | Output it. Stay in state 0. |
| 0 | 144 | Go to state 1. |
| 1 | 0 | Output 144 as a literal. Go to state 0. |
| 1 | V, not 0 | Set Len = L(V). If F(Len) = 2, go to state 2; if it is 3, go to state 3. |
| 2 | C | Len = Len + C. Go to state 3. |
| 3 | C | Copy Len + 3 bytes from distance D(V, C). Bytes before the start of output are zeros. |
| Factor | Method | L(X) | F(X) | D(X, Y) |
|---|---|---|---|---|
| 1 | 2 | low 7 bits | 2 if X = 127, else 3 | (upper 1 bit of X) × 256 + Y + 1 |
| 2 | 3 | low 6 bits | 2 if X = 63, else 3 | (upper 2 bits of X) × 256 + Y + 1 |
| 3 | 4 | low 5 bits | 2 if X = 31, else 3 | (upper 3 bits of X) × 256 + Y + 1 |
| 4 | 5 | low 4 bits | 2 if X = 15, else 3 | (upper 4 bits of X) × 256 + Y + 1 |
Implode (method 6)
A sliding dictionary with Shannon-Fano coding, set by flag bits 1 and 2. Bit 1 selects an 8 KiB or 4 KiB dictionary. Bit 2 selects three trees or two. With three trees, a literal tree of 256 entries comes first, followed by a length tree and a distance tree of 64 entries each. With two trees, literals are 8 raw bits.
The minimum match length is 3 with a literal tree, otherwise 2. Each tree is stored
as a byte count minus 1, then bytes each holding a high nibble (the number of codes with
this length, minus 1) and a low nibble (the bit length, minus 1). Codes are then assigned
from the longest length downwards, with their bits reversed, and returned to the original
order. For example, the bytes 02 42 01 13 give lengths 3, 3, 3, 3, 3, 2, 4, 4.
- A 1 bit: a literal, decoded with the literal tree or read as 8 raw bits.
- A 0 bit: a match. Read 7 low distance bits for an 8 KiB dictionary, or 6 for 4 KiB, then decode the upper 6 bits of the distance with the distance tree, then the length with the length tree. Add the minimum match length. If the length decoded equals 63 plus the minimum, read 8 more bits and add them. Copy that many bytes from distance + 1 bytes back.
PKWARE DCL Implode (method 10)
The PKWARE Data Compression Library’s implode, used by IBM’s old TERSE. APPNOTE gives
no details; Mark Adler’s public decoder, blast.c in zlib’s contrib folder, is
the reference. Two header bytes come first: 0 if literals are 8 raw bits or 1 if they are
coded, and the dictionary size code (4, 5 or 6 for 1, 2 or 4 KiB). Then a bit before each
item: 0 a literal, 1 a length and distance. Length codes use fixed tables, with extra
bits giving lengths of 2 to 519; length 519 is the end-of-data code. The distance has
its high 6 bits coded and the low bits raw: 2 low bits for length 2, otherwise the
dictionary code’s value. Bits are read low bit first.
bzip2 (method 12)
The member’s data is a complete bzip2 stream, with
its BZh header. APPNOTE refers to the external algorithm and gives no
framing of its own. Version needed is 4.6.
LZMA (method 14)
Not the same as a .lzma file. A small header comes first, then
raw LZMA1 data. Version needed is 6.3.
| Offset | Size | Name | Description |
|---|---|---|---|
0 | 1 | SDK major version | The LZMA SDK version of the writer. Readers ignore it. |
1 | 1 | SDK minor version | Readers ignore it. |
2 | 2 | Properties size | The size of the properties that follow: 5 in SDK 4.3. |
4 | 1 | Properties byte | The packed values of lc, lp and pb: (pb × 5 + lp) × 9 + lc. |
5 | 4 | Dictionary size | Little-endian. |
9 | varies | Data | LZMA1 data, without the 8-byte uncompressed size of a .lzma file. |
Flag bit 1 says the data ends with an end-of-stream marker. APPNOTE says one is optional but recommended. When bit 1 is clear, the reader stops at the uncompressed size from the header.
Python’s zipfile writes the version bytes 9 and 4
(struct.pack('<BBH', 9, 4, len(props)), LZMACompressor._init in
Lib/zipfile/__init__.py
of CPython v3.14.0, line 748). libzip writes 9 and 20 (0x09, 0x14, then the
two bytes 0x05 0x00 of the property size; zip_algorithm_xz.c of
libzip v1.12.1,
lines 322 to 325), and on reading checks only the two bytes of the property size, 0x05 0x00
(the same file, line 271), not the version bytes. An encryption header, if any, comes before
the LZMA header.
PPMd (method 98)
PPMd version I, revision 1 only. The compressed data follows a little-endian two-byte parameter word.
| Bits | Meaning |
|---|---|
| 0 to 3 | Model order minus 1: order 2 to 16, default 8. |
| 4 to 11 | Sub-allocator size minus 1, in megabytes: 1 to 256, default 50. |
| 12 to 15 | Restoration method: 0 restart (default), 1 cut off, 2 freeze. |
Version needed is 6.3. An order of 1 (bits 0 to 3 all zero) is not valid, and restoration methods above 2 are not defined.
The rest of the data is the output of a carry-less range coder (Subbotin’s): the decoder loads the first four bytes into its code register and reads one more byte each time the range narrows. What the coder codes is a byte at a time, predicted by Dmitry Shkarin’s PPMd variant I model. The model is not stored anywhere: the decoder builds the same one the encoder built, so every rule of the model is part of the format. That covers the contexts of up to order previous bytes and their symbol counts, the escapes to shorter contexts when a byte has not been seen in a context, the tables that estimate escape and binary-context probabilities, and the sub-allocator that holds it all in the given number of megabytes.
When the sub-allocator runs out of memory, the restoration method decides what happens.
Restart (0) throws the model away and starts again from an empty one. Cut off (1) keeps
the model but prunes it until at most three quarters of the memory is in use, unless
less than half is in use, in which case it restarts. Both are the same in the
RestoreModel function of 7-Zip’s
C/Ppmd8.c
(commit d3296e39e1f1f92c7b41c0c3848e65640428d42d of ip7z/7zip, lines 842 to 856: restart if the
method is restart or less than Size >> 1 is used, otherwise CutOff in a loop
while more than 3 * (Size >> 2) is used) and in libarchive’s
archive_ppmd8.c (commit 432ab464725aa99c53de7572979bd9bbbf382ed1, lines 601 to 615).
Freeze (2) in Shkarin’s original code stops the model growing. Both libraries leave that
code out, because their fixed code does not decode some freeze-mode files the way PPMd var. I rev. 1
did (Ppmd8.h in 7-Zip, lines 49 to 54 (the quotation is on line 52), archive_ppmd8_private.h in libarchive, lines 40 to 42:
“So we disable FREEZE mode support”). What they do with method 2 differs: 7-Zip’s
ZIP decoder (CPP/7zip/Compress/PpmdZip.cpp, lines 64 to 66) returns “not implemented” for it,
while libarchive’s archive_read_support_format_zip.c (line 2594, which rejects only values above 2) accepts it and, with the
freeze code left out, runs the cut-off path. The explorer also runs the cut-off path for 2, which is its own
choice, and has no freeze-mode file to compare with. The method makes no difference to data that never
fills the memory.
Writers end the data with an end mark: an escape out of the order-0 context, which stands for no byte at all. libarchive reads up to the end mark; the uncompressed size in the headers says the same thing.
Zstandard (method 93)
The member’s data is a standard Zstandard frame, as
libzip reads and writes it. Number 20 was used before 93 was assigned and is now
deprecated. APPNOTE’s version table does not list Zstandard. Python’s
zipfile writes version needed 63 (ZSTANDARD_VERSION = 63, used in ZipInfo.FileHeader: lines 73 and 543 of
Lib/zipfile/__init__.py
in CPython v3.14.0). libzip writes 20: zip_algorithm_zstd.c sets the algorithm’s version
needed to 20 (lines 265 and 279), under the comment “Version Required should be set to 63 (6.3)
because this compression method was only defined in appnote.txt version 6.3.7, but Winzip does not unpack it
if the value is not 20” (lines 254 to 256 of
libzip v1.12.1).
XZ (method 95)
The member’s data is a complete .xz stream. libzip writes it with an LZMA2 filter and a CRC-64 check and no extra header. It also writes version needed 20. The explorer reads every filter the .xz format defines in front of LZMA2 (Delta, and the branch converters for x86, PowerPC, IA-64, ARM, ARM-Thumb, SPARC, ARM64 and RISC-V), verifies each block’s CRC-32, CRC-64 or SHA-256 check, and lists the stream header, each block’s filter chain and sizes, the index and the footer.
WavPack (method 97)
The data is WavPack. The method field is 97 in both headers and the version fields match Deflate’s. Sample bytes should include unused bits, so a 12-bit sample is passed as 16 bits.
The member’s data is a WavPack stream whose blocks keep the original file’s header and
trailer (WavPack’s RIFF header and trailer sub-blocks) beside the coded samples. The
explorer decodes the samples with its WavPack decoder
and puts the header, the samples and the trailer back together, so the original .wav
file comes back byte for byte and is checked against the CRC-32. This has been tested
only with WavPack data from the site’s own test encoder: neither the reference
wavpack program nor a WinZip member was available to test against.
IBM methods (16, 18, 19)
For mainframes. Method 16, z/OS CMPSC, uses hardware compression and needs an expansion
dictionary stored in the member. A header comes first: a version byte (1), a flags and
symbol-size byte (high 4 bits flags, 0x80 expansion dictionary,
0x40 Deflate-compressed, and 0x20 and 0x10 reserved;
low 4 bits symbol size, 9 to 13), and a 4-byte dictionary length. Section 5.17 gives no byte
order for that length, so APPNOTE’s general rule applies (4.3.3 and 4.4.1.1: fields are
little-endian unless noted). The explorer reads it little-endian; only when that length
does not fit in the member and the big-endian reading does, it reads it big-endian, as a
mainframe writer might have written it, and says so in the viewer. That fallback is the
explorer’s own heuristic, not a rule of APPNOTE, and no public archive with method 16
was available to show what real writers do. Section 5.17 says only “length of the
expansion dictionary”; the explorer reads it as the number of bytes stored (so a
Deflate-compressed dictionary is that many compressed bytes, inflated to 8 bytes for each
possible index). That is the explorer’s reading: APPNOTE does not say whether the length
is of the compressed or the expanded dictionary. Then the expansion dictionary, then the compressed data. If
encrypted, these parts are encrypted as one unit. Only the expansion dictionary is
stored; the compression dictionary stays on the system that compressed. APPNOTE cites IBM
ESA/390 Data Compression (SA22-7208-01) for the algorithm.
Sources for the dictionary layout below. APPNOTE 5.17 does not give it. IBM’s
z/Architecture Principles of Operation (SA22-7832-10, March 2015, the public PDF
read for this page) describes the COMPRESSION CALL instruction (CMPSC, chapter 7): the
symbol size in bits and the dictionary size for each value of the 4-bit CDSS field (9
bits, 512 entries of eight bytes, 4K bytes; 10 bits, 1K entries; 11, 2K; 12, 4K; 13, 8K
entries, 64K bytes; other values are a specification exception), that a dictionary entry
is eight bytes, that the characters of one symbol can be counted up to at least 260 without a
data exception (the explorer’s limit of 260 matches this), and a flowchart of
the expansion process that uses the names PSL, CSL, OFST and PPTR. It does not give the
bit layout of an entry: for that it sends the reader to chapters 1 and 2 of SA22-7208-01,
which was not read. The entry layout described next, and the limit of PSL 5, come from the
Hercules emulator’s source (cmpsc.c, written to SA22-7208-01: the macros
ECE_psl, ECE_csl, ECE_pptr and ECE_ofst
and the function that fetches an expansion character entry), which was read but, being under
the Q Public License, is not reused.
The compressed data is a string of index symbols of the given size, most significant
bit first, with no gaps. An index below 256 is that byte. Any other index picks an 8-byte
entry of the expansion dictionary, at index × 8. The top three bits of the entry’s first
byte are PSL, the partial symbol length. With PSL 0 the entry is unpreceded: the next two
bits must be 0, the low three are CSL (1 to 7), and the CSL bytes after the first are the
characters that start the expansion. With PSL 1 to 5 the entry is preceded: the low five
bits of the first byte and the second byte give the predecessor’s index (13 bits), the
PSL bytes from the third on are characters, and the last byte, OFST, says how far into
the expansion they go. The expansion of the predecessor, followed in the same way,
fills the bytes before them; a predecessor below 256 is one byte. An expansion is at most
260 bytes. The explorer expands the data this way, after inflating the dictionary when
flag 0x40 is set, and lists the dictionary’s entries and each symbol.
APPNOTE gives method numbers only for 18 (IBM TERSE, new) and 19 (IBM LZ77 z Architecture). No published specification of either was found. The mainframe TERSE tool’s own output (AMATERSE, with its PACK and SPACK methods) can be read by open-source decoders such as the Open Mainframe Project’s TerseDecompress, but APPNOTE does not say that method 18 data takes that form, so the explorer names both methods and does not guess at their data. See method 10 above for the older TERSE.