Skip to main content
BZip2 is a compression method based on the Burrows-Wheeler Transform (BWT) and Huffman coding. It provides a good balance between compression ratio, speed, and memory usage.

Method ID

ID: 04 02 02 (hex) The BZip2 method is identified by the 3-byte sequence 04 02 02 in 7z archive format.
Note: ZIP archives use a different ID (04 01 0C) for BZip2, but this is not used in 7z. Always use 04 02 02 for 7z archives.

Overview

BZip2 is a widely-used compression algorithm that:
  • Uses block-sorting (Burrows-Wheeler Transform)
  • Applies Move-to-Front transform
  • Compresses with Huffman coding
  • Provides consistent, predictable compression ratios
  • Has moderate memory requirements
The BZip2 compression pipeline:
  1. Block Division: Input divided into blocks (100-900 KB)
  2. Burrows-Wheeler Transform: Sorts block rotations to group similar characters
  3. Move-to-Front: Converts repeated characters to small numbers
  4. Run-Length Encoding: Compresses runs of zeros
  5. Huffman Coding: Final entropy encoding
This multi-stage approach provides excellent compression while maintaining reasonable speed.

Algorithm Characteristics

Burrows-Wheeler Transform

Reversible transformation that groups similar bytes together for better compression

Block-Based Processing

Processes data in independent blocks, enabling parallel decompression

Move-to-Front

Exploits locality by moving recently seen characters to front of alphabet

Huffman Coding

Standard entropy coding for final compression stage

Compression Parameters

Range: 100 KB to 900 KB
Values: 1-9 (corresponds to 100KB, 200KB, …, 900KB)
Default: 9 (900 KB)
Block size determines:
  • Compression ratio: Larger blocks = better compression
  • Memory usage: Larger blocks = more memory
  • Parallelization: Each block can be processed independently
For most files, the default 900 KB block size provides the best compression. Use smaller blocks only if memory is limited.
BZip2 uses block size as its primary level parameter:
Unlike LZMA, BZip2 compression and decompression both have modest memory requirements.

Memory Requirements

Encoding

For default 900 KB blocks:
BZip2 compression typically requires:
  • Level 1 (100 KB): ~1.2 MB
  • Level 5 (500 KB): ~5.8 MB
  • Level 9 (900 KB): ~10.4 MB
Much less than LZMA/LZMA2 which can require hundreds of MB or even GB.

Decoding

For default 900 KB blocks:
Decompression uses about half the memory of compression, and both are significantly lower than LZMA methods.

Performance Characteristics

Typical performance on modern hardware (Intel Core i7, 3.5 GHz):Compression:
  • Level 1 (100 KB): ~8-10 MB/s
  • Level 5 (500 KB): ~6-8 MB/s
  • Level 9 (900 KB): ~5-7 MB/s
Decompression:
  • All levels: ~15-25 MB/s
Compression ratio:
  • Text files: 20-30% of original size
  • Executable files: 40-60% of original size
  • Multimedia files: 85-100% of original size (poor)

Compression Ratio Comparison

BZip2 provides a good middle ground for text compression.
For executables, LZMA2 with BCJ filter is superior to BZip2.
BZip2, like all compression methods, cannot compress already-compressed data (JPEG, PNG, MP3, etc.). Use Copy method instead.

Command Line Usage

BZip2 in 7z archives is single-threaded. For parallel compression, use LZMA2 with -mmt option.

BZip2 File Format

Standalone .bz2 files have this structure:
In 7z archives, BZip2 streams are wrapped in the 7z format and don’t include the standalone file headers.

BZip2 vs Other Methods

Use Cases

BZip2 is ideal for:
  • Memory-constrained systems: Uses much less RAM than LZMA
  • Compatibility: Widely supported across platforms
  • Balanced performance: Good ratio without excessive time
  • Log files: Excellent for text-based logs
  • Source code archives: Good compression with reasonable speed
  • Incremental backups: Predictable compression ratios
Avoid BZip2 for:
  • Maximum compression needed: Use LZMA2 or PPMd instead
  • Need for speed: Use Deflate for faster compression/decompression
  • Large files with multithreading: Use LZMA2 with -mmt
  • Already compressed data: Will not compress further
  • Binary executables: LZMA2 with BCJ filter is much better
Choose BZip2 if:
  • Memory < 50 MB available
  • Need wide compatibility
  • Prefer faster compression than LZMA
Choose LZMA2 if:
  • Memory > 100 MB available
  • Want maximum compression
  • Can use multithreading
  • Primarily use 7-Zip/p7zip tools
Choose Deflate if:
  • Need ZIP compatibility
  • Speed is critical
  • Very low memory required
Choose PPMd if:
  • Compressing text/structured data
  • Want absolute maximum compression
  • Speed is not important

Interoperability

BZip2 compressed data in 7z archives uses the standard BZip2 algorithm and is compatible with:
  • Command-line tools: bzip2, bunzip2, pbzip2
  • Libraries: libbz2, Apache Commons Compress
  • Languages: Python (bz2 module), Java, C/C++, Rust
  • Archive formats: 7z, tar.bz2, .bz2
Data compressed with 7-Zip’s BZip2 can be extracted with standard BZip2 tools and vice versa.

Parallel BZip2 Variants

7-Zip’s BZip2 implementation is single-threaded, but external tools provide parallel variants:
For faster BZip2 compression outside 7-Zip, use pbzip2 or lbzip2 with tar:

Best Practices

General recommendations:
  • Small files (< 100 KB): Use 100-300 KB blocks
  • Medium files (100 KB - 10 MB): Use 500-700 KB blocks
  • Large files (> 10 MB): Use 900 KB blocks (default)
  • Very limited memory: Use 100-200 KB blocks
Compare BZip2 with other methods:
BZip2 can be used in both solid and non-solid archives:
For BZip2, the difference between solid and non-solid is less dramatic than with LZMA, since BZip2 already uses block-based compression.

Error Handling

BZip2 is robust and provides good error detection:
  • CRC-32 checksums: Each block has a CRC for integrity
  • Magic numbers: Easy detection of format errors
  • Independent blocks: Corruption limited to single block
If a BZip2 compressed file is corrupted:
  • Only the corrupted block(s) will be affected
  • Other blocks may still be recoverable
  • Use bzip2recover tool to attempt recovery of .bz2 files

See Also