Skip to main content

Introduction to Zstandard

Zstandard, or zstd as short version, is a fast lossless compression algorithm, targeting real-time compression scenarios at zlib-level and better compression ratios. It’s backed by a very fast entropy stage, provided by Huff0 and FSE library.
Zstandard’s format is stable and documented in RFC8878. Multiple independent implementations are already available.

Why Zstandard?

Blazing fast performance

Compression speeds up to 510 MB/s and decompression up to 1550 MB/s at default settings

Excellent compression ratios

Achieves better compression ratios than zlib while being significantly faster

Flexible compression levels

Supports levels from -131072 (ultra-fast) to 22 (maximum compression)

Dictionary compression

Dramatically improves compression for small data using trained dictionaries

Benchmark highlights

For reference, several fast compression algorithms were tested and compared on a desktop featuring a Core i7-9700K CPU @ 4.9GHz running Ubuntu 24.04, using lzbench on the Silesia compression corpus:
Compressor nameRatioCompressionDecompress.
zstd 1.5.7 -12.896510 MB/s1550 MB/s
brotli 1.1.0 -12.883290 MB/s425 MB/s
zlib 1.3.1 -12.743105 MB/s390 MB/s
zstd 1.5.7 —fast=12.439545 MB/s1850 MB/s
zstd 1.5.7 —fast=42.146665 MB/s2050 MB/s
lz4 1.10.02.101675 MB/s3850 MB/s
snappy 1.2.12.089520 MB/s1500 MB/s
Zstandard offers the best balance of compression ratio and speed, outperforming zlib in both metrics.

Compression levels

The library supports regular compression levels from 1 up to 22. Levels >= 20, labeled --ultra, should be used with caution as they require more memory. The library also offers negative compression levels, which extend the range of speed vs. ratio preferences.
  • Negative levels (--fast=#): Faster compression and decompression at the cost of compression ratio
  • Levels 1-19: Balanced compression ratio and speed
  • Levels 20-22 (--ultra): Maximum compression ratio, requires more memory
Decompression speed is preserved and remains roughly the same at all settings, a property shared by most LZ compression algorithms.

Dictionary compression

The smaller the amount of data to compress, the more difficult it is to compress. Zstandard offers a training mode which can be used to tune the algorithm for a selected type of data. Using a dictionary, the compression ratio achievable on small data improves dramatically:
1

Create the dictionary

Train on sample data representative of your use case:
zstd --train FullPathToTrainingSet/* -o dictionaryName
2

Compress with dictionary

zstd -D dictionaryName FILE
3

Decompress with dictionary

zstd -D dictionaryName --decompress FILE.zst
The more data-specific a dictionary is, the more efficient it is. There is no universal dictionary.

Quick example

Here’s a simple example of compressing and decompressing data using the Zstandard C API:
#include <zstd.h>

// Compression
size_t const cBuffSize = ZSTD_compressBound(fSize);
void* const cBuff = malloc(cBuffSize);
size_t const cSize = ZSTD_compress(cBuff, cBuffSize, fBuff, fSize, 1);

// Decompression
unsigned long long const rSize = ZSTD_getFrameContentSize(cBuff, cSize);
void* const rBuff = malloc((size_t)rSize);
size_t const dSize = ZSTD_decompress(rBuff, rSize, cBuff, cSize);

What’s included

This reference implementation is provided as an open-source dual BSD OR GPLv2 licensed C library, and includes:
  • C library (libzstd): In-memory compression and decompression functions
  • Command line utility: Producing and decoding .zst, .gz, .xz and .lz4 files
  • Language bindings: Ports available for many programming languages on the Zstandard homepage

Deployment at scale

Zstandard is deployed within Meta and many other large cloud infrastructures to compress humongous amounts of data in various formats and use cases. It is continuously fuzzed for security issues by Google’s oss-fuzz program.

Get started

Installation

Install Zstandard using your preferred package manager or build from source

Quick start guide

Get up and running with a working compression example in minutes

Build docs developers (and LLMs) love