Skip to content

Data compression and archive tools

current

This wiki is about media encoding, but you will still compress logs, project folders, caches, subtitles and source tarballs. These pages cover the general-purpose tools. None of them shrink video, audio or image files: those are already compressed, and re-compressing them saves almost nothing.

You want…UseTypical command
A good default for anything on Linux/macOSzstdzstd -T0 file
Backups of a directory with Unix metadatatar + zstd or xztar --zstd -cf backup.tar.zst dir/
Smallest file you will compress oncexz or 7zxz -9e file
A file anyone can open without installing softwareZIPzip -r archive.zip dir/
Static web assetsbrotli (+ gzip fallback)brotli -q 11 file
Maximum compatibility, scripts, old systemsgzipgzip -9 -k file
Incremental, deduplicated, versioned backupszpaqzpaq a backup.zpaq dir/
Opening old .tar.bz2 filesbzip2bzip2 -d file.bz2
FormatArchive?StrengthWeakness
gzipNo (single stream)Universal, fast, tiny memoryWeakest ratio
bzip2NoBetter than gzip on textSlow, superseded
xzNoVery small output, cheap to decompressSlow and memory-hungry to compress
zstdNoFast at every level, close to xz at the top, multi-threadedLess universal than gzip; HTTP window limit
brotliNoBest for web text (built-in dictionary)Slow at high quality; web-oriented
tarYes (no compression)Preserves Unix metadata; pairs with any compressorNo index, no random access
ZIPYes (per-file compression)Opens everywhere, random accessWeaker ratio; mixed support for newer methods and AES
7zYes (solid)Strong ratio, AES-256, big dictionariesSlow to extract single files; drops Unix owner/ACLs
ZPAQYes (journaling)Deduplication, every version restorableSlow, rare

A “single stream” format compresses one byte sequence. For directories, put them in tar or zip first, which is why you see .tar.gz, .tar.xz and .tar.zst.

Levels trade time for size, with sharply diminishing returns. zstd -3 and gzip -6 are the fast defaults; zstd -19 and xz -6 are slow but noticeably smaller; xz -9e, 7z -mx=9, zstd --ultra -22 and brotli -q 11 are for files compressed once and read many times. If you compress frequently (logs, intermediate files, network transfers), stay at zstd -1…-9. zstd needs -T0 to use all cores; xz has done so by default since 5.6.0.

Servers and browsers negotiate a coding with Accept-Encoding and Content-Encoding. gzip, br (Brotli) and zstd are the three registered codings that matter. gzip works everywhere; br is accepted by browsers over HTTPS; zstd is advertised by Chrome and Edge 123+, Firefox 126+ and Safari 26.3+. Always keep a fallback and serve with Vary: Accept-Encoding. zstd for HTTP is limited to an 8 MiB window (RFC 9659), so files made with --long or --ultra levels cannot be served that way. xz, 7z and bzip2 are not HTTP codings.

zstd -t, xz -t, gzip -t, bzip2 -t, brotli -t, unzip -t, 7z t and zpaq x -test verify integrity without extracting. The built-in checks catch accidental corruption, but not tampering: publish a SHA-256 alongside downloads.