Skip to main content
LZMA (Lempel-Ziv-Markov chain Algorithm) is an improved version of the famous LZ77 compression algorithm. It was improved in the way of maximum increasing of compression ratio, keeping high decompression speed and low memory requirements for decompressing.

Method ID

ID: 03 01 01 (hex) The LZMA method is identified by the 3-byte sequence 03 01 01 in 7z archive format.

Overview

LZMA provides excellent compression ratios through:
  • Dictionary-based LZ77 algorithm
  • Range encoding for entropy coding
  • Markov chain-based probability model
  • Optimized match finding
LZMA is the original algorithm used in .lzma files and was the default method in 7z archives before LZMA2 was introduced. It remains widely used for single-threaded compression.

Properties File Format

LZMA compressed files have a 13-byte header:

Compression Parameters

LZMA supports the following encoding properties defined in LzmaEnc.h:13-39:
Type: UInt32
Range: (1 << 12) to (1 << 27) for 32-bit, (1 << 12) to (3 << 29) for 64-bit
Default: 1 << 24 (16 MB)
The dictionary size determines how far back the encoder can reference previous data. Larger dictionaries provide better compression but require more memory.
The dictionary size is automatically adjusted based on compression level:
  • Level 0-4: 1 << (level * 2 + 16)
  • Level 5+: 1 << (level + 20)
Type: int
Range: 0 to 8
Default: 3
Number of high bits of the previous byte used as context for literal encoding.
Higher values can improve compression of text files but increase memory usage.
Type: int
Range: 0 to 4
Default: 0
Number of low bits of the current position used as context for literal encoding.
The constraint lc + lp <= 4 is recommended but not enforced. Higher values significantly increase memory usage.
Type: int
Range: 0 to 4
Default: 2
Number of low bits of the current position used as context for match length encoding.
Type: int
Range: 0 to 9
Default: 5
Compression level affects multiple parameters automatically:
Type: int
Range: 0 (fast) or 1 (normal)
Default: 1
  • Fast (0): Hash chain mode, faster compression, lower ratio
  • Normal (1): Binary tree mode, slower compression, better ratio
Type: int
Range: 5 to 273
Default: 32 (level < 7) or 64 (level >= 7)
Number of fast bytes. Higher values can improve compression ratio but slow down encoding.
Type: int
Range: 0 (hash chain) or 1 (binary tree)
Default: 1
Type: int
Range: 2, 3, or 4
Default: 4
Type: UInt32
Range: 1 to 1 << 30
Default: 32
Maximum number of match candidates to check.
Type: int
Range: 1 or 2
Default: 2 (if multithreading available)
LZMA supports only limited multithreading (up to 2 threads) for match finding. For better multithreading support, use LZMA2.
Type: unsigned
Range: 0 or 1
Default: 0
Whether to write an end-of-payload marker (EOPM).

Memory Requirements

Encoding

Memory required for compression (LzmaEnc.c:41):
Where:
  • dictSize: Dictionary size in bytes
  • state_size: (4 + (1.5 << (lc + lp))) KB
  • Default state_size (lc=3, lp=0): 16 KB
For level 5 (16 MB dictionary): ~190 MB for encodingFor level 9 (256 MB dictionary): ~2.9 GB for encoding

Decoding

Memory required for decompression:
  • Stack usage: 200-400 bytes for local variables
  • Default state_size: 16 KB
  • Dictionary buffer: Equal to dictionary size used during encoding
Decompression requires significantly less memory than compression. A file compressed with a 256 MB dictionary only needs ~256 MB to decompress.

API Usage

Encoding

Decoding

Error Codes

LZMA encoder and decoder can return the following status codes:

Performance Characteristics

Typical performance on modern hardware (Intel Core i7, 3.5 GHz):Compression:
  • Level 5: ~2-3 MB/s
  • Level 9: ~1-2 MB/s
Decompression:
  • ~20-40 MB/s (single-threaded)
Compression ratio:
  • Text files: 15-25% of original size
  • Executable files: 30-50% of original size
  • Multimedia files: 70-95% of original size (poorly compressible)

Command Line Usage

For new archives, consider using LZMA2 instead of LZMA. LZMA2 provides better multithreading support and handles incompressible data more efficiently.

See Also