Twelve formats, three jobs. An archive bundles files and metadata into one stream but compresses nothing. A compressor shrinks one data stream but knows nothing about files. Some containers do both at once. Keeping the two jobs straight is most of the map - the rest is picking a point on the ratio/speed curve.
| Type | Job | Formats |
|---|---|---|
| A · Archive | stores files + metadata, no compression of its own | TAR |
| C · Compression | one data stream in, a smaller one out | GZIP · BZIP2 · XZ · ZSTD · LZ4 · LZIP · ZLIB · BROTLI |
| B · Both | container with built-in codecs | ZIP · 7-ZIP · RAR |
| Tier | Meaning | Formats |
|---|---|---|
| Modern | actively developed, the current defaults | ZSTD · LZ4 · BROTLI |
| Active | widely used, mature | ZIP · TAR · GZIP · XZ · 7-ZIP · LZIP · ZLIB |
| Legacy | compatibility only | BZIP2 · RAR |
.tar.gz, .tar.xz and .tar.zst all exist: same archive, swapped compressor. The integrated containers (.zip, .7z, .rar) fuse the two. Section 03 draws it out.
Who is who. Algorithms first: nearly everything is LZ77 plus an entropy coder - the differences are the window size, the coder (Huffman vs range coding vs finite state entropy), and how much CPU the format is willing to spend.
| Format | Ext / spec | Type | Algorithm | Techniques | Typical use |
|---|---|---|---|---|---|
| ZIP | .zip | B | DEFLATE | LZ77 + Huffman | software distribution, documents, cross-platform, legacy compatibility |
| TAR | ustar / pax | A | none | POSIX archive layer | backups, packaging, pairs with a compressor |
| GZIP | .gz | C | DEFLATE | LZ77 + Huffman | web content (HTTP), logs, tar.gz |
| BZIP2 | .bz2 | C | BWT + RLE + Huffman | block-sorting | text, better ratio than gzip, legacy systems |
| XZ | .xz · LZMA2 | C | LZMA2 | LZ77 + range coder + BCJ filters | maximum compression, OS images, ISOs |
| 7-ZIP | .7z | B | LZMA2 | BCJ + range coder + others | high-compression archives, large datasets |
| RAR | v5 · proprietary | B | LZSS variant + range coder | predictive filters, PPMd text mode | archival with recovery record, Windows ecosystem |
| ZSTANDARD | .zst · RFC 8878 | C | LZ77 + FSE | finite state entropy, trainable dictionaries | the modern default: logs, backups, data, ML, containers |
| LZ4 | .lz4 | C | LZ77, very fast | no entropy coding | real-time systems, DB caches, game assets |
| LZIP | .lz | C | LZMA1 | simpler container, integrity checks | long-term archival, alternative to XZ |
| ZLIB | RFC 1950 | C | DEFLATE | LZ77 + Huffman | embedded systems, PNG, the base under gzip and zip |
| BROTLI | .br · RFC 7932 | C | LZ77 + static dict | ~120 KB web-token dictionary + Huffman | web (HTTPS), text and fonts, better ratio than gzip |
TAR carries no compression of its own; it is the archive layer that bundles files and metadata, then a separate codec compresses the resulting stream. That separation is why the .tar.* combinations exist at all - pick the archive once, swap the compressor to taste.
the two-layer model files / dirs ──► TAR (archive: files + metadata, 1:1) ──► CODEC ──► one file tar + GZIP = .tar.gz tar + XZ = .tar.xz tar + ZSTD = .tar.zst integrated containers (archive + codec fused): ZIP = .zip 7-ZIP = .7z RAR = .rar
the same idea in commands# archive layer stays tar; only the codec flag changes tar -czf site.tar.gz site/ # gzip: everywhere, fast enough tar -cJf site.tar.xz site/ # xz: max ratio, slow tar --zstd -cf site.tar.zst site/ # zstd: the modern default # integrated: archive + codec in one step zip -r site.zip site/ 7z a -mx=9 site.7z site/ # bare stream compressors zstd -19 --long=27 big.log # long-window mode lz4 -1 assets.bin
Speeds are normalized to zstd level 3 = 1.00x, single core, modern x86-64; higher is faster. Decompression is always faster than compression for the same format. Ratios are typical / best-case on mixed real-world data.
| Format | Ratio typ | Ratio best | Compress | Decompress |
|---|---|---|---|---|
| ZIP | 2:1 - 4:1 | 10:1+ | 0.45x | 0.35x |
| TAR | 1:1 | 1:1 | n/a | n/a |
| GZIP | 2:1 - 6:1 | 10:1+ | 0.60x | 0.35x |
| BZIP2 | 3:1 - 5:1 | rarely 6:1+ | 0.25x | 0.30x |
| XZ | 5:1 - 8:1 | rarely 10:1+ | 0.15x | 0.25x |
| 7-ZIP | 5:1 - 8:1 | rarely 10:1+ | 0.15x | 0.25x |
| RAR | 3:1 - 6:1 | rarely 7:1+ | 0.30x | 0.35x |
| ZSTANDARD | 2:1 - 4:1 | rarely 5:1+ | 1.00x | 1.00x |
| LZ4 | 2:1 - 2.5:1 | rarely 3:1+ | ~4.0x+ | ~10x+ |
| LZIP | 4:1 - 8:1 | rarely 10:1+ | 0.20x | 0.30x |
| ZLIB | 2:1 - 4:1 | 10:1+ | 0.20x | 0.35x |
| BROTLI | 4:1 - 8:1 | rarely 10:1+ | 0.60x | 0.50x |
denser ▲ compress speed, log scale (zstd-3 = 1x) 8:1 | XZ 7-ZIP | LZIP 6:1 | BROTLI 5:1 | RAR 4:1 | BZIP2 3:1 | ZLIB ZIP GZIP ZSTD 2:1 | LZ4 +────────────────────────────────────────────────────── 0.1x 0.3x 0.6x 1x 4x+ slow + dense corner fast + loose corner
The flags that decide integration: can it stream through a pipe, can you seek into the middle, does it compress files as one solid block, will it use your cores.
| Format | Solid | Stream | Seek | Multi-thread |
|---|---|---|---|---|
| ZIP | no - per file | yes - sequential | yes - per file | part - tools vary |
| TAR | no | yes - sequential | no | no |
| GZIP | no | yes - sequential | no | part - pigz ¹ |
| BZIP2 | no | yes - sequential | no | no |
| XZ | no | yes - sequential | yes - mt decode | yes |
| 7-ZIP | yes - default | part - seq. read | no | yes |
| RAR | yes - default | part - seq. read | no | yes |
| ZSTANDARD | no | yes - seekable | yes - seekable | yes |
| LZ4 | no | yes - seekable | yes - seekable | yes |
| LZIP | no | yes - sequential | no | no |
| ZLIB | no | yes - sequential | no | no - zlib-ng ² |
| BROTLI | no | yes - sequential | no | yes |
¹ pigz: parallel gzip implementation (compression multi-threading). ² zlib-ng: drop-in zlib replacement with SIMD; enables faster decode.
The window is how far back a format can reference. A 32 KB DEFLATE window cannot see repetition 1 MB apart; a 128 MB zstd window can. Log scale:
ZIP 32 KB █ GZIP 32 KB █ ZLIB 32 KB █ LZ4 64 KB ██ BZIP2 900 KB ██████ (block size) BROTLI 16 MB ███████████ → 1 GB large-window ext XZ 64 MB █████████████ → ~4 GB max 7-ZIP 64 MB █████████████ → ~4 GB max ZSTD 128 MB ██████████████ → ≤2 GB (trained dict ≤2 GB) LZIP 1 GB ██████████████████ RAR 1.3 GB ███████████████████
What happens when bits flip. Three tiers: formats that can repair or route around damage, formats that resync at the next block boundary and lose only one block, and streams where corruption kills everything after it.
| Tier | Behavior | Formats |
|---|---|---|
| Strong | recovers from corrupted data | RAR (recovery record) · ZSTD (frame checksums) · LZ4 · LZIP (lziprecover) |
| Block-level | recovers to the next block / frame boundary | BZIP2 · BROTLI |
| Weak / none | corruption typically breaks the rest of the stream | GZIP · ZLIB · XZ · 7-ZIP (CRC detects, nothing repairs) · TAR |
lziprecover, or keep external parity.
| Need | Pick |
|---|---|
| Best balance of ratio + speed | ZSTANDARD |
| Maximum compression | XZ / 7-ZIP |
| Maximum speed | LZ4 |
| Web / text compression | BROTLI |
| Error recovery built in | RAR |
| Long-term auditability | LZIP |
| Plain archive, no compression | TAR |