A .zst file is one or more frames, Zstandard frames or skippable frames,
one after another; decompressing it gives the frames’ contents joined. This page follows
RFC 8878. Numbers are
little-endian. Compressed blocks are described on
compressed blocks.
Zstandard frame
| Field | Size | Description |
|---|---|---|
Magic_Number | 4 | FD2FB528, stored 28 B5 2F FD. |
Frame_Header_Descriptor | 1 | See below. |
Window_Descriptor | 0 or 1 | Absent when Single_Segment_Flag is set. See window size. |
Dictionary_ID | 0, 1, 2 or 4 | The ID of the dictionary the frame needs, little-endian. When absent, the decoder has to know which dictionary to use. A small ID may be written in the 4-byte form. The ranges up to 32,767 and from 231 up are for dictionaries registered with IANA; a payload that names an unregistered ID in those ranges is an error. Any other value is for private arrangement. |
Frame_Content_Size | 0, 1, 2, 4 or 8 | Size of the decompressed content, little-endian. A 1-, 4- or 8-byte value is read directly (0 to 255, 0 to 232 − 1, 0 to 264 − 1); a 2-byte value has 256 added (256 to 65,791). Absent means unknown. A small size may be written in any variant that can hold it. |
| Blocks | … | At least one block and no upper limit; the last has Last_Block set. |
Content_Checksum | 0 or 4 | With Content_Checksum_Flag: the low 4 bytes of XXH64, seed 0, of the decoded content, stored little-endian. A decoder may ignore it. |
Frame header descriptor
| Bits | Name | Meaning |
|---|---|---|
| 7 and 6 | Frame_Content_Size_Flag | Size of Frame_Content_Size: 0 → 0 bytes, or 1 byte when Single_Segment_Flag is set; 1 → 2; 2 → 4; 3 → 8. |
| 5 | Single_Segment_Flag | The content is one segment: no window descriptor, and the window size is the content size, which must be present. |
| 4 | Unused | A decoder must not interpret it; it might signal a non-mandatory property in a future version. An encoder must set it to 0. |
| 3 | Reserved | Must be 0; a decoder must check that it is not set. A future revision may use it for a feature that must be understood to decode the frame. |
| 2 | Content_Checksum_Flag | A 4-byte checksum ends the frame. |
| 1 and 0 | Dictionary_ID_Flag | Size of Dictionary_ID: 0 → 0, 1 → 1, 2 → 2, 3 → 4 bytes. |
Window size
The window descriptor’s bits 7 to 3 are the exponent and bits 2 to 0 the mantissa.
windowLog = 10 + Exponent; windowBase = 1 << windowLog;
Window_Size = windowBase + (windowBase / 8) × Mantissa. That is 1 KB to
3.75 TB. Decoders should support at least 8 MB; the RFC recommends that encoders not
go above that for general use. The minimum is 1 KB; the maximum is
(1 << 41) + 7 × (1 << 38) bytes. With Single_Segment_Flag there is
no descriptor and the window is Frame_Content_Size, which a decoder with a
smaller memory limit may reject (8 MB is the recommended minimum there too). The frame
header as a whole is 2 to 14 bytes.
Blocks
Each block starts with a 3-byte little-endian header:
| Bits | Name | Meaning |
|---|---|---|
| 0 | Last_Block | This is the frame’s last block. |
| 1 and 2 | Block_Type | 0 Raw_Block: the bytes as they are. 1 RLE_Block: one byte, repeated Block_Size times. 2 Compressed_Block. 3 Reserved, invalid. |
| 3 to 23 | Block_Size | Bytes of content after the header; for an RLE block, the number of repeats (the content is 1 byte). |
A block holds at most Block_Maximum_Size of content, the smaller of the
window size and 128 KB, constant for the frame. It limits both the decompressed and the
compressed size of any block. If a compressed block would be larger than the raw one,
the RFC recommends a raw block. Block type 3 is corrupt data and a decoder must reject
it. The block 01 00 00 is an empty last raw block. A compressed block needs
the earlier decoded data within the window, the three repeat offsets and the Huffman
tree and FSE tables of earlier compressed blocks (or of the dictionary); raw and RLE
blocks do not change the offsets.
Skippable frames
| Field | Size | Description |
|---|---|---|
Magic_Number | 4 | Any of 184D2A50 to 184D2A5F (little-endian); all 16 are valid. |
Frame_Size | 4 | Size of the user data, not counting the magic number or this field; unsigned 32-bit little-endian. |
User_Data | … | Anything; skipped by decoders, which resume after it. |
RFC 8878 gives no tagging method for skippable frames, says they match the skippable frames of LZ4, and warns that one can carry tracking data (such as a UUID) in a stream of concatenated frames. Its uses beyond that, such as seek tables, are not in the RFC.
Dictionaries
A dictionary prepares the decoder with content and entropy tables, which helps on small inputs. A frame names its dictionary by ID; the dictionary itself is a separate file:
| Field | Size | Description |
|---|---|---|
Magic_Number | 4 | EC30A437, stored 37 A4 30 EC. |
Dictionary_ID | 4 | Any value except 0 (no dictionary). For public distribution the ranges up to 32,767 and from 231 up must not be used. |
Entropy_Tables | … | In this order: the Huffman table for literals, the FSE table for offsets, the FSE table for match lengths, the FSE table for literal lengths, each in the format used inside compressed blocks. They fill the Treeless literals and Repeat_Mode slots. Then three offset values, 4 bytes little-endian each (12 bytes), replacing the default 1, 4 and 8; each must be less than the dictionary size. |
Content | … | The rest of the dictionary: data that acts as the “past” in front of the content. While the output decoded so far is at most Window_Size, offsets may reach back into the dictionary, even past Window_Size; after that the dictionary is no longer reachable. |
RFC 8878 also allows “raw content” dictionaries, free of any format restriction except that they must be at least 8 bytes; they act as just the content part. The RFC does not say how the decoder gets a dictionary: it is supplied out of band.
XXH64
The content checksum is XXH64 with seed 0 (xxHash specification 0.2.0, read 2026-11-13); only the low 4 bytes are
stored. Everything is modulo 264, reads are little-endian, <<< is rotate left.
Constants: P1 = 0x9E3779B185EBCA87, P2 = 0xC2B2AE3D27D4EB4F,
P3 = 0x165667B19E3779F9, P4 = 0x85EBCA77C2B2AE63, P5 = 0x27D4EB2F165667C5.
round(acc, lane) = ((acc + lane × P2) <<< 31) × P1.
- Input of 32 bytes or more:
acc1 = seed + P1 + P2,acc2 = seed + P2,acc3 = seed,acc4 = seed − P1; each 32-byte stripe has four 8-byte lanes,accN = round(accN, laneN). Thenacc = (acc1 <<< 1) + (acc2 <<< 7) + (acc3 <<< 12) + (acc4 <<< 18)and, for each accumulator in turn,acc = ((acc ^ round(0, accN)) × P1) + P4. Shorter input:acc = seed + P5. acc += length.- Remaining bytes: for each 8:
acc = (((acc ^ round(0, lane)) <<< 27) × P1) + P4; then, if 4 or more remain, one 4-byte lane:acc = (((acc ^ (lane × P1)) <<< 23) × P2) + P3; then for each byte:acc = ((acc ^ (byte × P5)) <<< 11) × P1. - Avalanche:
acc ^= acc >> 33; acc *= P2; acc ^= acc >> 29; acc *= P3; acc ^= acc >> 32.
Example
A small file compressed with default settings:
28 B5 2F FD magic
24 descriptor: Single_Segment (20), Content_Checksum (04), 1-byte content size
0C Frame_Content_Size 12
… blocks
xx xx xx xx checksum