Skip to content

The Edge of the Cyber World See the latest

Apps

Which Compressor for Which Job? We Tested Zstd, Brotli, XZ, Gzip and LZ4 on Real Files

If you serve web pages, precompress what you can with Brotli at its highest setting and keep gzip as the fallback. If you write backups, logs or build artifacts, switch from gzip to zstd at its default level. If you publish one archive that thousands of people will download, xz and high-level zstd are close on size, and zstd unpacks about four times faster. That is what we found after running five compressors at 17 settings over the Python 3.13.1 source tarball and 200 Tech Insider article pages exactly as our server sends them. Our raw results are downloadable.

The same tool can be the right answer for a backup and the wrong one for a web server, so the results are organized by job, with the exact commands at the end.

Job Use Why, from our tests
Static web files, compressed at deploy Brotli 11, with a gzip copy as fallback 19.1% smaller than gzip -6 across 200 real pages and their CSS/JS
Web responses compressed per request Brotli 5 9.0% smaller than gzip -6, and faster to compress
Backups, logs, build output zstd 3 Smaller than gzip -6, about 5x faster to compress, 2x faster to unpack
When CPU time is the limit zstd 1 As fast as single-threaded LZ4 here, with 28% smaller output
Release archives zstd 22 with –long=27, or xz -9 for the smallest file xz -9 is about 2% smaller; zstd unpacks over 4x faster

How we tested

We built gzip 1.15, Brotli 1.2.1, zstd 1.5.7, XZ Utils 5.8.4 and LZ4 1.11.1 from their official source releases and ran them on a shared cloud server with four virtual CPUs (a DigitalOcean Premium Intel instance). Every tool ran on one thread, with input and output held in memory so the disk did not affect timings. For the Python tarball, each setting got one warm-up run and three timed runs and we report the median; the web test measured sizes only. Every decompressed file was compared byte for byte with the original. Some runs shared the machine with other benchmark jobs, each pinned to its own virtual CPU.

Serving a website: Brotli for static files, and test file by file

We fetched 200 Tech Insider article pages from our own server, uncompressed and fully rendered, plus the six CSS and JavaScript files those pages load: 54.2 MB in 206 files. Our pages carry most of their styling and scripts inline, so the HTML is the bulk of what a visitor downloads. We then compressed each file on its own, because a browser receives one compressed response per file.

Setting All 206 files Average article page vs gzip -6
Uncompressed 54.2 MB 270 KB
gzip -6 (a common server default) 12.0 MB 59.9 KB baseline
gzip -9 11.9 MB 59.6 KB 0.5% smaller
Brotli 5 10.9 MB 54.5 KB 9.0% smaller
Brotli 11 9.7 MB 48.4 KB 19.1% smaller
zstd 3 (its default) 12.3 MB 61.1 KB 2.1% larger
zstd 19 10.6 MB 52.8 KB 11.8% smaller

Brotli’s lead on HTML has a simple cause: the format, defined in RFC 7932, carries a built-in dictionary of common words and markup fragments, which helps on text. Zstd has no built-in dictionary, which is why its default setting came out slightly larger than gzip on our pages. Results depend on your pages, so test your own before switching.

Brotli 11 is far too slow to run on every request; it compressed at about a third of a megabyte per second in our tarball test. It is meant for files you compress once at build or deploy time and serve many times. For responses generated on the fly, Brotli 5 was 9% smaller than gzip -6 and compressed faster than it in our tarball run. Browsers say what they accept, and MDN’s Content-Encoding reference lists gzip, br and zstd among its values, so keep a gzip copy for clients that do not send br. If your front end is built with a bundler, the step that writes Brotli and gzip copies belongs in the build; our Vite vs Webpack comparison covers where each tool fits in that pipeline.

Why archive-style tests flatter web compression

We also compressed the same 206 files as a single tar archive. Brotli 11 then reached a ratio of 23.4 to 1 and zstd 19 reached 21.9 to 1, against 5.6 and 5.1 to 1 file by file. Every page repeats the same header, menus, styles and footer, and in one archive the compressor only has to store that once. Gzip barely changed (4.55 against 4.51 to 1), because it can only look back 32 KB and cannot see from one page to the next. A web server compressing separate responses gets none of that gain, so if a benchmark compresses a folder of web assets as one blob, its web figures are not the savings your visitors will see.

Backups, logs and build output: zstd by default, and even when CPU is tight

For data you write more often than you read, compression speed matters as much as size. On the 109.6 MB Python 3.13.1 source tarball, a mix of C, Python and documentation much like a typical code repository, zstd at its default level beat gzip’s default on size and on both speeds, at the cost of more memory: about 44 MiB to compress against under 3 MiB for gzip.

Setting Size ratio Compress Decompress
gzip -6 3.71 : 1 21.7 MB/s 188 MB/s
gzip -9 3.74 : 1 7.9 MB/s 229 MB/s
zstd 1 3.57 : 1 257 MB/s 660 MB/s
zstd 3 3.83 : 1 112 MB/s 399 MB/s
LZ4 1 2.57 : 1 255 MB/s 549 MB/s

Zstd 3 produced slightly smaller output than gzip -6, compressed about five times faster and decompressed about twice as fast. Turning gzip up to -9 bought less than 1% in size for a run almost three times slower, which is rarely worth it. The surprise was LZ4. Its reputation is speed, and its project page quotes compression above 500 MB/s per core, but on one thread with this data the LZ4 command-line tool compressed at 255 MB/s, no faster than zstd -1, while zstd -1’s output was 28% smaller. LZ4’s library is still a fine choice inside software that calls it directly; for a backup script, zstd -1 is the better fast option. Either way the drive may set the pace first: our NVMe vs SATA comparison has the write speeds, and our external SSD vs hard drive test shows how slow a USB hard drive is by comparison.

The zstd format is an IETF RFC, and for a tar-based backup script the switch is usually a one-flag change. Multithreading (-T0) makes zstd faster still on large files; we kept every test to one thread so the tools compete on equal terms.

Archives you publish once: xz and high-level zstd

Source releases, firmware images and installers are compressed once and unpacked by everyone who downloads them, so size and unpacking speed matter and compression time mostly does not.

Setting Size ratio Decompress Memory to compress Memory to decompress
xz -6 (xz default) 4.85 : 1 79 MB/s 95 MiB 10 MiB
xz -9 4.98 : 1 80 MB/s 675 MiB 66 MiB
zstd 19 4.74 : 1 363 MB/s 198 MiB 12 MiB
zstd 22 with –long=27 4.88 : 1 350 MB/s 840 MiB 109 MiB
Brotli 11 4.91 : 1 214 MB/s 215 MiB 20 MiB

Xz -9 still produced the smallest file, but only by about 2% against zstd 22 with a long match window, and zstd unpacked the result more than four times faster. For a large download that is unpacked on many machines, that speed difference is felt by every user, while the 2% is felt mainly by the server bill. A --long=27 file unpacks with a plain zstd -d; if you go above 27, the person unpacking must pass the same --long value or a larger memory limit, so document it next to the download.

What unpacking costs in memory

Benchmarks rarely report decompression memory, but it decides what a router, a small virtual server or an embedded board can open. In our runs gzip needed about 2 MiB to decompress, xz -6 about 10 MiB, zstd 19 about 12 MiB and Brotli about 20 MiB. The settings that squeeze hardest raise that floor: xz -9 output needed 66 MiB to unpack and zstd 22 with --long=27 needed 109 MiB. If the machine that opens your archive has a few hundred megabytes of RAM shared with everything else, pick the setting with that in mind, not just the smallest file.

Patch your decompressors too

Decompressors read untrusted input all day, which makes them attack surface. The XZ Utils project page currently lists a buffer overflow, CVE-2026-34743 in lzma_index_append(), alongside the 2024 backdoor incident, CVE-2024-3094. Microsoft’s Security Update Guide lists CVE-2026-111497, a Google-assigned buffer overflow in the Brotli decoder. None of that is a reason to avoid a format; it is a reason to take compression libraries from your operating system’s updates and to rebuild statically linked tools when a decoder fix lands.

The commands we used

These use the compression levels we tested, on the versions listed above. We ran every benchmark on one thread, so the -T0 multithreading flag shown here was not part of our timings.

# Static web files: keep the original, write .br and .gz next to it
brotli -q 11 -k page.html
gzip -9 -k page.html

# Backups and logs: zstd default level, all cores
zstd -3 -T0 backup.tar

# Fast option when CPU time is the limit
zstd -1 -T0 data.tar

# A release archive with a long match window, and how to unpack it
zstd --ultra -22 --long=27 -T0 release.tar
zstd -d release.tar.zst

# Smallest file when unpacking speed and memory do not matter
xz -9 -T1 -k release.tar

Where your numbers will differ

Absolute speeds depend on the processor, and a shared cloud machine adds some noise; the comparisons between tools on the same data are what carry over to your hardware. Pages with less inline code than ours will compress differently, so run the web test on your own HTML. Text and code compress well, while photos, video and files that are already compressed barely shrink with any of these tools. The full results are available to download: Python source tarball, all 17 settings, LZ4 run single-threaded (CSV) and 200 web pages and their assets, file by file and as one archive (CSV).

Related Coverage

Source: Tech Insider