Compression Formats Deep Dive

Landscape · Matrix · Pipelines · Ratio vs Speed · Capabilities · Recovery · Choosing
12 archive + compression formats // ratios and speeds vs a zstd-3 baseline // Calgary · Silesia · enwik corpora

The Landscape

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.

TypeJobFormats
A · Archivestores files + metadata, no compression of its ownTAR
C · Compressionone data stream in, a smaller one outGZIP · BZIP2 · XZ · ZSTD · LZ4 · LZIP · ZLIB · BROTLI
B · Bothcontainer with built-in codecsZIP · 7-ZIP · RAR

Generations

TierMeaningFormats
Modernactively developed, the current defaultsZSTD · LZ4 · BROTLI
Activewidely used, matureZIP · TAR · GZIP · XZ · 7-ZIP · LZIP · ZLIB
Legacycompatibility onlyBZIP2 · RAR
Separation of concerns The unix lineage keeps the archive layer and the codec separate, which is why .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.

The Format Matrix

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.

FormatExt / specTypeAlgorithmTechniquesTypical use
ZIP.zipBDEFLATELZ77 + Huffmansoftware distribution, documents, cross-platform, legacy compatibility
TARustar / paxAnonePOSIX archive layerbackups, packaging, pairs with a compressor
GZIP.gzCDEFLATELZ77 + Huffmanweb content (HTTP), logs, tar.gz
BZIP2.bz2CBWT + RLE + Huffmanblock-sortingtext, better ratio than gzip, legacy systems
XZ.xz · LZMA2CLZMA2LZ77 + range coder + BCJ filtersmaximum compression, OS images, ISOs
7-ZIP.7zBLZMA2BCJ + range coder + othershigh-compression archives, large datasets
RARv5 · proprietaryBLZSS variant + range coderpredictive filters, PPMd text modearchival with recovery record, Windows ecosystem
ZSTANDARD.zst · RFC 8878CLZ77 + FSEfinite state entropy, trainable dictionariesthe modern default: logs, backups, data, ML, containers
LZ4.lz4CLZ77, very fastno entropy codingreal-time systems, DB caches, game assets
LZIP.lzCLZMA1simpler container, integrity checkslong-term archival, alternative to XZ
ZLIBRFC 1950CDEFLATELZ77 + Huffmanembedded systems, PNG, the base under gzip and zip
BROTLI.br · RFC 7932CLZ77 + static dict~120 KB web-token dictionary + Huffmanweb (HTTPS), text and fonts, better ratio than gzip
Three DEFLATE wearers ZIP, GZIP and ZLIB are the same core algorithm in three containers: ZLIB is the bare RFC 1950 stream, GZIP wraps it with a header + CRC for files, ZIP wraps per-file entries with a central directory. Same 32 KB window, same ratios.

Layering and Pipelines

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
Per-file vs solid Integrated containers make a choice tar never has to: compress each file separately (ZIP - random access, weaker ratio on many small files) or as one solid block (7-ZIP, RAR - better ratio, no random access). Section 05 tables it.

Ratio vs Speed

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.

FormatRatio typRatio bestCompressDecompress
ZIP2:1 - 4:110:1+0.45x0.35x
TAR1:11:1n/an/a
GZIP2:1 - 6:110:1+0.60x0.35x
BZIP23:1 - 5:1rarely 6:1+0.25x0.30x
XZ5:1 - 8:1rarely 10:1+0.15x0.25x
7-ZIP5:1 - 8:1rarely 10:1+0.15x0.25x
RAR3:1 - 6:1rarely 7:1+0.30x0.35x
ZSTANDARD2:1 - 4:1rarely 5:1+1.00x1.00x
LZ42:1 - 2.5:1rarely 3:1+~4.0x+~10x+
LZIP4:1 - 8:1rarely 10:1+0.20x0.30x
ZLIB2:1 - 4:110:1+0.20x0.35x
BROTLI4:1 - 8:1rarely 10:1+0.60x0.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
Benchmark notes Aggregated from public corpora (Calgary, Silesia, enwik8/9), large text/JSON logs, and OS image sets, 2023-2024. Reference system: Ryzen 9 7950X (16C/32T), 64 GB DDR5, Ubuntu 24.04 LTS. Tools: zstd 1.5.6, 7-Zip 24.07, xz 5.6.2, gzip 1.13, brotli 1.1.0, lz4 1.9.4, zlib-ng 2.1.6. Single-core unless noted. Real numbers vary with data, level, and hardware.

Format Capabilities

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.

FormatSolidStreamSeekMulti-thread
ZIPno - per fileyes - sequentialyes - per filepart - tools vary
TARnoyes - sequentialnono
GZIPnoyes - sequentialnopart - pigz ¹
BZIP2noyes - sequentialnono
XZnoyes - sequentialyes - mt decodeyes
7-ZIPyes - defaultpart - seq. readnoyes
RARyes - defaultpart - seq. readnoyes
ZSTANDARDnoyes - seekableyes - seekableyes
LZ4noyes - seekableyes - seekableyes
LZIPnoyes - sequentialnono
ZLIBnoyes - sequentialnono - zlib-ng ²
BROTLInoyes - sequentialnoyes

¹ pigz: parallel gzip implementation (compression multi-threading). ² zlib-ng: drop-in zlib replacement with SIMD; enables faster decode.

Window / dictionary range

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   ███████████████████

Error Recovery

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.

TierBehaviorFormats
Strongrecovers from corrupted dataRAR (recovery record) · ZSTD (frame checksums) · LZ4 · LZIP (lziprecover)
Block-levelrecovers to the next block / frame boundaryBZIP2 · BROTLI
Weak / nonecorruption typically breaks the rest of the streamGZIP · ZLIB · XZ · 7-ZIP (CRC detects, nothing repairs) · TAR
Checksums are not recovery XZ and 7-ZIP carry integrity checks, so they will tell you the archive is damaged - and then nothing can be repaired. For archives that must survive bit rot, that is the wrong tier: use RAR's recovery record, LZIP with lziprecover, or keep external parity.
The archival pick LZIP exists for exactly this: a deliberately simple container, built-in integrity checking, and a dedicated repair tool - which is why it shows up in long-term archival guidance as the auditable alternative to XZ.

Choosing a Format

NeedPick
Best balance of ratio + speedZSTANDARD
Maximum compressionXZ / 7-ZIP
Maximum speedLZ4
Web / text compressionBROTLI
Error recovery built inRAR
Long-term auditabilityLZIP
Plain archive, no compressionTAR
// landscape · matrix · pipelines · ratio vs speed · capabilities · recovery · choosing //