Skip to main content
Deflate is a widely-used compression algorithm that combines LZ77 compression with Huffman coding. It is the standard compression method in ZIP archives and is used in many other formats including gzip and PNG.

Method ID

ID: 04 01 08 (hex) The Deflate method is identified by the 3-byte sequence 04 01 08 in 7z archive format (ZIP method ID). Deflate64 ID: 04 01 09 (hex) - Enhanced version with larger window

Overview

Deflate is one of the most widely-deployed compression algorithms:
  • Used in ZIP, gzip, PNG, HTTP compression, and many more
  • Fast decompression speed
  • Low memory requirements
  • Moderate compression ratio
  • Excellent compatibility across platforms and languages
Deflate has been the standard ZIP compression method since the 1990s. Its wide compatibility and fast decompression make it ideal for web content, application data, and scenarios where decompression speed matters more than file size.

Algorithm Overview

Deflate combines two compression techniques:
The first stage uses LZ77 sliding window compression:
  • Window size: 32 KB (Deflate) or 64 KB (Deflate64)
  • Look-ahead buffer: 258 bytes
  • Match finding: Finds repeated sequences in the sliding window
  • Output: Literals (uncompressed bytes) and length/distance pairs
The 32 KB window limit means Deflate cannot reference data more than 32 KB back, which limits compression ratio for files with long-range repetition.
The second stage applies Huffman coding to the LZ77 output:
  • Dynamic Huffman trees: Custom trees built for each block
  • Two trees: One for literals/lengths, one for distances
  • Block types: Stored (uncompressed), fixed Huffman, or dynamic Huffman
Huffman coding assigns shorter bit codes to more frequent symbols:
Deflate automatically chooses between fixed and dynamic Huffman trees, selecting whichever gives better compression for each block.

Compression Levels

Deflate supports 10 compression levels (0-9):
No compression, data stored as-is:
Use for already-compressed data (JPEG, MP3, etc.) to avoid overhead.
Quick compression with minimal processing:
  • Limited match searching
  • Smaller hash tables
  • Faster encoding
Use for temporary files, network transmission, or when CPU time is more valuable than bandwidth.
Standard ZIP compression level:
  • Good balance of speed and ratio
  • Default for most ZIP tools
  • Moderate memory usage
Slowest but best compression:
  • Exhaustive match searching
  • Larger hash tables
  • More CPU time per byte
Level 9 is 3-5x slower than level 6 but typically provides only 2-5% better compression. Use for archives that will be decompressed many times.

Memory Requirements

Compression

Deflate compression memory usage:
Deflate compression uses very little memory compared to LZMA (190+ MB) or BZip2 (10+ MB). This makes it ideal for embedded systems and mobile devices.

Decompression

Deflate decompression memory usage:
Decompression requires only ~40 KB regardless of compression level. This tiny memory footprint is why Deflate is used in firmware, bootloaders, and memory-constrained environments.

Performance Characteristics

Typical performance on modern hardware (Intel Core i7, 3.5 GHz):Compression:
  • Level 1: ~50-80 MB/s
  • Level 6: ~15-25 MB/s
  • Level 9: ~5-10 MB/s
Decompression:
  • All levels: ~200-400 MB/s
Compression ratio:
  • Text files: 25-40% of original size
  • Executable files: 40-60% of original size
  • Multimedia files: 95-100% of original size (minimal compression)
Deflate decompression is 10-20x faster than compression and 5-10x faster than LZMA decompression.

Deflate vs Deflate64

Deflate64 (Enhanced Deflate) is an improved version:
Deflate64 support is limited:
  • Windows built-in ZIP: Yes
  • 7-Zip: Yes (decode only, does not encode)
  • WinZip: Yes
  • Info-ZIP unzip: No
  • Many Linux tools: No
Use standard Deflate for maximum compatibility.

Compression Ratio Comparison

Deflate provides fair compression with excellent speed.
For executables, LZMA2 significantly outperforms Deflate.
Deflate (as gzip) is the standard for web compression due to universal browser support.
HTTP servers typically use gzip (Deflate) at level 6 for on-the-fly compression. Pre-compressed static assets often use level 9 or Brotli.

Command Line Usage

For ZIP files, 7-Zip automatically uses Deflate. Explicitly specifying it is only needed for 7z archives.

Deflate File Formats

Deflate is used in multiple file formats:
Standard ZIP format with Deflate compression:
ZIP is the most compatible archive format worldwide.
Single-file compression format:
Gzip can only compress one file. For multiple files, combine with tar: tar.gz or .tgz
Tar archive with gzip compression:
PNG uses Deflate for lossless image compression:
PNG tools use Deflate levels 6-9 depending on optimization level.
Web servers use gzip (Deflate) for content compression:
Common level 6 for real-time compression, level 9 for static files.

Use Cases

Deflate is ideal for:
  • ZIP compatibility: Need to create standard ZIP archives
  • Fast decompression: Application startup, web content delivery
  • Low memory: Embedded systems, mobile devices, IoT
  • Web content: HTTP compression, static assets
  • Cross-platform: Maximum compatibility required
  • Real-time compression: Network protocols, streaming
Avoid Deflate for:
  • Maximum compression: Use LZMA2 or PPMd instead
  • Large files with patterns: LZMA2 handles better
  • Archival storage: Better ratio from LZMA2 saves space
  • Already compressed: Use Copy/Store method

Deflate vs Other Methods

Deflate’s main advantages are:
  1. Universal compatibility (every platform, every language)
  2. Very fast decompression (10-20x faster than LZMA)
  3. Minimal memory (usable on any device)
  4. Proven reliability (30+ years of widespread use)

Best Practices

Choose compression level based on use case:
  • Level 1: Temporary files, network transmission
  • Level 6: General-purpose ZIP archives
  • Level 9: Archives for distribution, static web assets
When to use each format:Use ZIP when:
  • Need compatibility with all systems
  • Recipients may not have 7-Zip installed
  • Fast decompression is priority
Use 7z when:
  • Need maximum compression (LZMA2)
  • All users have 7-Zip or compatible tools
  • Archival storage (size matters more than compatibility)
Deflate benefit from solid archives:
Standard ZIP tools create non-solid archives. 7-Zip’s ZIP format can create solid archives for better compression, but this may reduce compatibility.
Always test archives after creation:

Advanced Topics

Configure web server compression:Nginx:
Apache:
Pre-compress static files for faster serving:
Configure server to serve pre-compressed versions.
Deflate stream structure:
Each block can use different compression strategies.

Troubleshooting

If Deflate compression is ineffective:
  1. Check if data is already compressed
  2. Try higher compression level
  3. Consider LZMA2 for better ratio
If ZIP archives don’t open on other systems:
  1. Use standard ZIP format
  2. Avoid advanced features
    • Don’t use solid mode for ZIP
    • Don’t use encryption (or use ZipCrypto)
    • Don’t use Deflate64
  3. Test with multiple tools

See Also