Skip to content

zstd

currentMigrated from docs/data/zstd.mdx at 37c3317fd058; modified for Encode Wiki · CC BY-SA 4.0

Zstandard (zstd) is Yann Collet’s compressor, developed at Facebook (now Meta) and specified in RFC 8878. It compresses and decompresses faster than gzip at a better ratio, its high levels approach xz, and decompression speed barely depends on the level. That makes it the sensible default for archives, backups, logs, container images and intermediate files. Arch Linux packages are zstd-compressed, and the Linux kernel, btrfs, SquashFS and OpenZFS all support it.

Terminal window
zstd file # file.zst, level 3, source kept
zstd -19 -T0 file # slower, much smaller, all cores
zstd --ultra -22 -T0 file # maximum; needs lots of memory
zstd -d file.zst # decompress
zstd -dc file.zst | less # to stdout
zstd -t file.zst # test integrity

Unlike gzip and xz, zstd keeps the input file by default (--rm deletes it). Output has a .zst extension.

OptionEffect
-1 … -19Compression level; default 3. -19 is about the useful limit
--ultra -20…-22Even slower and memory-hungry, with small gains; the decoder also needs more memory
--fast=NNegative levels, faster than -1 with worse ratios
-T0Use all cores (default is 1); also speeds up higher levels a lot
--long[=27]Long-distance matching with a 128 MiB window; helps on big files with distant repeats (VM images, tarballs of similar trees)
--adaptChange the level on the fly to match how fast the output is being consumed (good for piping over a network)
-D dictUse a trained dictionary; zstd --train files… builds one. Big wins on many small similar files

Levels 3–9 are the sweet spot for logs, backups and anything compressed repeatedly. Use 19 for things compressed once and read many times.

Larger windows need matching decompression settings

Section titled “Larger windows need matching decompression settings”

With --long=N for N above 27, the decompressor must be given --long=N too (or --memory=…), otherwise it refuses the file to protect itself from huge allocations. Archives made with the default window decompress anywhere.

zstd compresses one stream, not a directory, so combine it with tar:

Terminal window
tar --zstd -cf backup.tar.zst dir/
tar -I 'zstd -19 -T0' -cf backup.tar.zst dir/
tar -xf backup.tar.zst

The zstd binary can also read and write gzip, xz and lzma streams (--format=gzip). 7-Zip can unpack .zst files since 24.01 but does not create them.

zstd is a registered HTTP content coding. Chrome and Edge 123, Firefox 126 and Safari 26.3 (iOS, or macOS 26.3 and later) advertise it in Accept-Encoding; see Can I use. HTTP zstd limits the window to 8 MiB (RFC 9659), so do not serve files compressed with --long or --ultra levels (20–22) as Content-Encoding: zstd. Level 19 and below stay within the limit. Brotli (brotli) is the established alternative for static web assets and has wider browser support.

vs.zstd
gzipFaster at a similar or better ratio, and multithreaded
xzSlightly worse ratio at max, but decompresses several times faster
brotliFaster; brotli wins on small text/web files thanks to its built-in dictionary