Zstandard, usually abbreviated zstd, is a lossless data compression algorithm and file format that combines compression ratios comparable to zlib or better with much higher speed, especially during decompression. In server performance work, it is used to shrink HTTP responses, logs, backups, database pages and network transfers while keeping CPU overhead low.
Zstandard was created by Yann Collet, released as open source in 2016 and standardized for the web in RFC 8878, which defines the zstd content coding for HTTP. Its defining trait is a very wide tuning range: the same format serves real-time compression at hundreds of megabytes per second and slow archival compression that rivals xz.
How Zstandard compresses data
Zstandard follows the classic LZ77 plus entropy coding design. A match finder searches previous data inside a sliding window for repeated sequences and replaces them with references of length and offset. The remaining literals and the match descriptions are then encoded with Huffman coding for literals and Finite State Entropy (FSE), an implementation of tabled asymmetric numeral systems, for the sequence fields.
FSE is a key reason for its speed: it reaches near-arithmetic-coding efficiency while decoding with simple table lookups and few branches. Data is organized in frames containing blocks of up to 128 KB, and each frame can carry a content checksum and the original size. Because the decoder does almost the same work regardless of the compression level, decompression speed stays high even for data compressed at the slowest settings.
Two further features distinguish it from older codecs. Trained dictionaries capture common content from samples, which greatly improves compression of small payloads such as JSON records. Long-distance matching extends the window to hundreds of megabytes, which helps with large backups containing distant duplicates.
Zstandard compression levels and parameters
The compression level is the main control. Levels run from negative “fast” levels through 1 to 22, with level 3 as the default. Levels above 19 are called ultra levels and require much more memory on both sides because of larger windows. Exact throughput depends heavily on hardware and data, so the figures below are indicative ranges for one modern core.
| Level range | Compression speed | Relative ratio | Typical server use |
|---|---|---|---|
| Negative levels | Above 500 MB/s | Lowest | Real-time streams, caches |
| 1 to 3 | About 300-500 MB/s | Similar to gzip -6 | HTTP responses, logs, file systems |
| 4 to 12 | About 50-200 MB/s | Moderately better | Nightly backups, packages |
| 13 to 19 | About 5-40 MB/s | High | Static assets precompressed once |
| 20 to 22 | Below 5 MB/s | Highest | Long-term archives |
Other important parameters include the window size (--long or windowLog), the number of worker threads (-T), and the checksum flag. Decompression typically runs at one gigabyte per second or more per core across all levels, which is why compressing once at a high level pays off for data that is read many times.
Zstandard compared with gzip and Brotli
Zstandard competes mainly with Gzip compression (DEFLATE) and Brotli on servers. Gzip is universal but slow for its ratio; Brotli achieves excellent ratios for text with its built-in web dictionary but compresses slowly at high levels. The table summarizes the practical differences.
| Codec | Strength | Weakness | Browser support |
|---|---|---|---|
| Gzip | Universal compatibility | Lower ratio, slower decompression | All browsers |
| Brotli | Best ratio for static text | Slow at high levels | All modern browsers |
| Zstandard | Best speed-to-ratio balance | Newer HTTP support | Chromium-based browsers and Firefox |
For dynamic HTTP responses, zstd at low levels often matches Brotli’s ratio at a fraction of the CPU cost, which reduces response time and raises requests per second. For precompressed static assets, Brotli at level 11 remains a strong choice. Outside the browser, in backups, logs, file systems and databases, zstd has largely displaced gzip.
Where Zstandard improves server performance
Zstandard helps wherever bandwidth, disk I/O or storage is the bottleneck and spare CPU exists. The decision table below maps common server scenarios to sensible settings.
| Scenario | Suggested setting | Reason |
|---|---|---|
| Dynamic web responses | Level 3 to 6 | Low latency, good ratio |
| Static assets | Level 19, precompressed | Compressed once, served often |
| Log rotation | Level 3 with multithreading | Fast, roughly halves gzip time |
| Database or file system | Level 1 to 3 | Transparent with minimal I/O stall |
| Backup archives | Level 10 to 19 with --long | Finds distant duplicates |
| Small JSON messages | Trained dictionary | Small inputs lack context |
Common integrations include Nginx and Apache modules, Btrfs and ZFS transparent compression, MySQL and PostgreSQL features, Kafka message batches, the Linux kernel and initramfs images, and tar --zstd for archives. In each case the benefit comes from moving fewer bytes through slow resources while the decoder adds little latency.
Limitations and common mistakes with Zstandard
Zstandard is not free of trade-offs, and several configuration errors cancel its advantages. Typical problems include the following.
- Using high levels for dynamic content: level 19 per request wastes CPU and raises tail latency.
- Compressing already compressed data: JPEG, video and ZIP files gain nothing and cost CPU.
- Ignoring memory limits: ultra levels and
--longwindows need matching decoder memory, which embedded clients may lack. - Missing fallback negotiation: clients without zstd support must still receive gzip through Accept-Encoding handling.
- Losing dictionaries: data compressed with a dictionary cannot be decoded without the same dictionary.
- Compression and secrets: compressing attacker-influenced input together with secrets enables BREACH-style attacks, as with any codec.
The idea in brief
Zstandard is a way to make data smaller quickly so that servers can store and send it faster. It looks for repeated pieces and writes short notes such as “same as earlier” instead of repeating them.
Its special talent is speed. Packing can be fast or very thorough depending on a dial, while unpacking is always fast. That makes it useful for websites, logs and backups alike.
A practical scenario
An online retailer runs a JSON API behind Nginx that returns product listings averaging 180 KB per response. The servers used gzip at level 6, and under evening peaks the CPU on the web tier reached 85 percent, while median response time rose noticeably. The operations team enabled zstd at level 3 for clients that advertise it and kept gzip as a fallback for others.
After the change, compressed responses were slightly smaller than before and compression CPU time fell by more than half on the measured workload. Peak CPU dropped to about 60 percent, the 95th-percentile response time improved, and the team postponed adding two servers. Nightly log archives were also switched to zstd -T0, which cut rotation time from forty minutes to under ten.