Every Linux user eventually types tar -xzf from memory and tar -czf with a moment of doubt. The flags are the easy part. The real question is which compressor to put behind them, and the answer has shifted: gzip is no longer the obvious default, xz is smaller but slow, and zstd has become hard to ignore. To settle it with numbers, a 55 MB tar of 1,292 real files, the Python 3.11 standard library from an Ubuntu 24.04 system, was compressed and decompressed with each tool on a two-core sandbox, using GNU tar 1.35, gzip 1.12, bzip2, xz 5.4.5 and zstd 1.5.5.
The commands
Creating an archive
tar -czf project.tar.gz project/ # gzip
tar -cJf project.tar.xz project/ # xz
tar --zstd -cf project.tar.zst project/ # zstd
c creates, f names the archive file, and the compression letter picks the program: z for gzip, j for bzip2, J for xz.
Letting the file name decide
GNU tar can choose the compressor from the archive’s name. Its manual describes the --auto-compress (-a) option, which selects the compression program based on the suffix of the archive file name. In the test, the same command with three names produced three formats, confirmed by file:
$ tar -caf p.tar.zst -C src project
$ tar -caf p.tar.xz -C src project
$ tar -caf p.tar.gz -C src project
p.tar.zst: Zstandard compressed data (v0.8+)
p.tar.xz: XZ compressed data, checksum CRC64
p.tar.gz: gzip compressed data, from Unix
-C src changes into src first, so the archive holds project/ rather than src/project/.
Extracting needs no compression flag
The same manual says reading a compressed archive is simpler still: tar recognizes its format automatically. tar -xf p.tar.zst -C x1 extracted the zstd archive with no --zstd flag. The z in tar -xzf has been optional on GNU tar for years; it still works, it just is not needed.

The benchmark
Results
Each compressor read the 54,988,800-byte tar and wrote the compressed file; then the file was decompressed to nowhere. All runs used a single thread so the numbers compare the algorithms, not the core count:
| Compressor | Ratio | Size | Compress | Decompress |
|---|---|---|---|---|
| zstd -1 | 2.87 | 19.2 MB | 0.16 s | 0.06 s |
| zstd -3 (default) | 3.13 | 17.6 MB | 0.24 s | 0.11 s |
| gzip -6 (default) | 3.06 | 18.0 MB | 1.96 s | 0.33 s |
| gzip -9 | 3.09 | 17.8 MB | 13.67 s | 0.34 s |
| bzip2 -9 (default) | 3.53 | 15.6 MB | 4.00 s | 1.66 s |
| zstd -19 | 3.94 | 14.0 MB | 20.75 s | 0.08 s |
| xz -6 (default) | 4.19 | 13.1 MB | 21.35 s | 0.77 s |
| xz -9 | 4.58 | 12.0 MB | 24.03 s | 0.70 s |
What stands out
zstd at its default level produced a slightly smaller file than gzip at its default, about eight times faster, and decompressed three times faster. gzip -9 spent seven times longer than gzip -6 to save 0.2 MB. xz produced the smallest files by a clear margin, at roughly 90 to 100 times the compression time of default zstd. And zstd -19, nearly as slow to compress as xz, decompressed in 0.08 seconds, about nine times faster than xz.
How this compares with published figures
The zstd project’s own benchmark, run on the standard Silesia test corpus, shows the same pattern at the fast end: zstd level 1 at a ratio of 2.896, compressing at 510 MB/s, against zlib (the library behind gzip) at level 1 with 2.743 at 105 MB/s. Different data and hardware give different absolute numbers, but the ranking held in this test.
Choosing a compressor
For backups and anything made often: zstd
At the default level, zstd matched gzip’s size in an eighth of the time. For a nightly backup, a log archive or anything compressed more often than it is read, that is the best balance found here.
For files published once and downloaded many times: xz
A source tarball or a release archive is compressed once and downloaded thousands of times. Paying 21 seconds once to make every download 27 percent smaller than gzip is a good trade, which is why many projects publish .tar.xz. If download size matters and so does extraction speed for the people downloading, zstd -19 came within 7 percent of xz’s size and decompressed nine times faster.
For compatibility: gzip
gzip is everywhere: every Linux system, every macOS install, every language’s standard library, and countless tools that expect .tar.gz. When the person receiving the file might not have zstd, gzip is the safe choice. There was no case in this test where -9 was worth it.
The data matters more than the tool
The same three compressors were run on two slices of the corpus: 11.9 MB of Python source text, and 15.2 MB of compiled files (.pyc bytecode and .so libraries):
| Data | gzip -6 | zstd -3 | xz -6 |
|---|---|---|---|
| Source text | 4.43 | 4.55 | 6.25 |
| Compiled files | 2.77 | 2.94 | 4.04 |
Text shrank to roughly a quarter of its size under any of them, and xz’s lead was largest there. Binaries compressed far less. A folder of logs or source code will compress dramatically; a folder of photos or videos will not.
Compressed data does not compress again
The 18.0 MB gzip file from the benchmark was fed back through each compressor. gzip got it to 17.85 MB, xz to 17.81 MB, and zstd made it slightly larger, 17.97 MB against 17.99 MB for the original. JPEG photos, MP4 video, ZIP files and most modern office documents are already compressed internally, so wrapping them in .tar.gz mostly costs time. For those, a plain .tar or a fast zstd level is enough.
bzip2
bzip2 sat between gzip and xz on size but was the slowest of all to decompress, at 1.66 seconds. It had no clear advantage over the others in this test.

Using both cores
Multi-threaded compression
xz and zstd can split work across cores with -T0, which means “use all of them.” On the two-core test machine:
| Compressor | Single thread | -T0 (2 cores) |
|---|---|---|
| zstd -19 | 20.75 s | 11.66 s |
| xz -6 | 21.35 s | 10.56 s |
Both nearly halved their time. Multi-threaded xz splits the input into blocks, which cost a little size: the threaded file was 13.19 MB against 13.11 MB single-threaded, about half a percent.
Through tar
tar does not pass -T0 on its own. The -I option (--use-compress-program) lets a full command line through:
tar -I 'zstd -19 -T0' -cf backup.tar.zst data/
tar -I 'xz -6 -T0' -cf release.tar.xz project/
The resulting archives extract normally with tar -xf, single-threaded or not.
Memory is the other cost
Peak memory, measured with GNU time, separated the tools further. gzip compressed in about 2 MB. zstd -3 used 18 MB and zstd -19 about 100 MB. xz -6 used 96 MB and xz -9 used 173 MB. Decompressing an xz -9 archive needed 56 MB, against 10 MB for xz -6 and 13 MB for zstd -19. On a small board like a Raspberry Pi with little memory, the higher levels can matter as much as the time.
Looking inside and taking out one file
Listing
tar -tf lists contents without extracting, again with no compression flag needed:
$ tar -tf p.tar.xz
project/
project/readme.txt
project/docs/
project/docs/guide.md
Extracting one file
Naming a member extracts just that one. tar -xf p.tar.gz -C x3 project/docs/guide.md created only x3/project/docs/guide.md, with the directory path recreated around it. The name has to match the listing exactly, including the leading directory.
Dropping the top folder
Archives usually wrap everything in one directory. --strip-components=1 removes it on the way out: extracting with it put docs and readme.txt directly into the target directory instead of under project/.

Two warnings worth knowing
Absolute paths
Archiving with a full path, tar -czf abs.tar.gz /var/tmp/cmp/src/project/readme.txt, made tar print:
tar: Removing leading `/' from member names
and the archive listed the file as var/tmp/cmp/src/project/readme.txt. That is a safety feature: extracting it later writes under the current directory instead of overwriting the real path. Using -C and relative paths avoids the message and keeps archives tidy.
Checking an archive arrived intact
A truncated download fails partway through extraction. Running tar -tf on the archive reads it end to end and fails early if it is damaged. A published checksum is the stronger check, covered in the earlier post on verifying downloads with sha256sum. For moving archives between machines, the earlier post on scp, rsync and sftp applies; already-compressed archives gain nothing from compression in transit.
Sources
- gzip (Creating and Reading Compressed Archives), GNU tar manual: https://www.gnu.org/software/tar/manual/html_node/gzip.html
- Zstandard, Real-time data compression algorithm (project site): https://meta.github.io/zstd/
