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
Input:  "the quick brown fox jumps over the lazy dog"
Output: "the quick brown fox jumps over ", <length=4, distance=10>, "lazy dog"
        (references "the " from earlier in the stream)
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:
Frequent symbol: 3 bits (e.g., space = 010)
Rare symbol:    12 bits (e.g., 'Z' = 111010110101)
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):
LevelStrategySpeedCompressionUse Case
0Store onlyFastestNoneAlready compressed data
1FastVery fastMinimalQuick compression
2-3FastFastFairBalanced speed/ratio
4-5MediumMediumGoodDefault usage
6DefaultMediumGoodStandard (ZIP default)
7-8SlowSlowBetterMaximum compression
9MaximumSlowestBestArchive distribution
No compression, data stored as-is:
# Store without compression
7z a -m0=Deflate -mx=0 archive.7z file.txt
Use for already-compressed data (JPEG, MP3, etc.) to avoid overhead.
Quick compression with minimal processing:
  • Limited match searching
  • Smaller hash tables
  • Faster encoding
# Fast compression
7z a -m0=Deflate -mx=1 archive.7z folder/
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
# Default Deflate (level 6)
7z a -m0=Deflate archive.7z file.txt
Slowest but best compression:
  • Exhaustive match searching
  • Larger hash tables
  • More CPU time per byte
# Maximum Deflate compression
7z a -m0=Deflate -mx=9 archive.7z folder/
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:
Memory ≈ 256 KB + (level_dependent_buffer)
LevelMemory (Approximate)
0< 1 KB
1~8 KB
2-3~16 KB
4-5~32 KB
6~128 KB
7-8~256 KB
9~512 KB
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:
Memory ≈ 32 KB (window) + 8 KB (overhead) ≈ 40 KB
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:
FeatureDeflateDeflate64
Method ID04 01 0804 01 09
Window Size32 KB64 KB
Match LengthUp to 258 bytesUp to 65,536 bytes
CompressionGood~5-10% better
SpeedFastSlightly slower
CompatibilityUniversalLimited (requires Deflate64 decoder)
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

MethodCompression RatioSpeed
PPMd100% (best)Very Slow
LZMA2110-120%Slow
BZip2120-130%Medium
Deflate140-160%Fast
Deflate provides fair compression with excellent speed.
MethodCompression RatioSpeed
LZMA2 + BCJ100% (best)Slow
BZip2130-150%Medium
Deflate150-180%Fast
For executables, LZMA2 significantly outperforms Deflate.
MethodCompression RatioUse Case
Deflate (gzip)100% (standard)HTTP compression
Brotli80-90%Modern browsers
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

# Compress with Deflate (default level 6)
7z a -m0=Deflate archive.7z file.txt

# Compress with Deflate64
7z a -m0=Deflate64 archive.7z file.txt

# Set compression level (0-9)
7z a -m0=Deflate -mx=9 archive.7z folder/

# Fast compression (level 1)
7z a -m0=Deflate -mx=1 archive.7z folder/

# Store only (no compression)
7z a -m0=Deflate -mx=0 archive.7z images/*.jpg

# Create ZIP file with Deflate
7z a -tzip archive.zip folder/

# Maximum Deflate compression in ZIP
7z a -tzip -mx=9 archive.zip folder/
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:
# Create ZIP with Deflate
7z a -tzip archive.zip folder/

# Extract ZIP
7z x archive.zip
ZIP is the most compatible archive format worldwide.
Single-file compression format:
# Create gzip file
7z a -tgzip file.txt.gz file.txt

# Extract gzip file
7z x file.txt.gz
Gzip can only compress one file. For multiple files, combine with tar: tar.gz or .tgz
Tar archive with gzip compression:
# Create tar.gz
7z a -ttar temp.tar folder/
7z a -tgzip archive.tar.gz temp.tar

# Or in one step with tar command
tar -czf archive.tar.gz folder/

# Extract with 7-Zip
7z x archive.tar.gz
7z x archive.tar
PNG uses Deflate for lossless image compression:
PNG format:
  - Filters: Prepare image data for compression
  - Deflate: Compress filtered data
PNG tools use Deflate levels 6-9 depending on optimization level.
Web servers use gzip (Deflate) for content compression:
Content-Encoding: gzip
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
# Create compatible ZIP for sharing
7z a -tzip documents.zip *.pdf *.docx

# Compress web assets
7z a -tgzip -mx=9 style.css.gz style.css
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
# Wrong: Deflate for long-term archive
7z a -tzip archive.zip large_dataset/

# Right: LZMA2 for better compression
7z a archive.7z large_dataset/

Deflate vs Other Methods

FeatureDeflateLZMA2BZip2PPMd
Method ID04 01 082104 02 0203 04 01
Compression RatioFair (5/10)Excellent (9/10)Good (7/10)Excellent (10/10)
Compression SpeedFast (7/10)Slow (3/10)Medium (5/10)Very Slow (2/10)
Decompression SpeedVery Fast (9/10)Medium (6/10)Medium (6/10)Slow (4/10)
Memory (Compress)Very Low (~512 KB)High (~200 MB)Low (~10 MB)High (~64 MB)
Memory (Decompress)Very Low (~40 KB)Medium (~50 MB)Low (~4 MB)High (~64 MB)
Window Size32 KBUp to 1.5 GB900 KBVariable
MultithreadingNoYesNoNo
StreamingYesYesYesYes
CompatibilityUniversalLimitedWideLimited
Year Introduced1993200919962001
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
# Quick backup (speed priority)
7z a -tzip -mx=1 backup.zip /important/data/

# Distribution archive (size priority)
7z a -tzip -mx=9 release.zip software/
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)
# Sharing with non-technical users
7z a -tzip documents.zip files/

# Personal archive or technical users
7z a archive.7z files/
Deflate benefit from solid archives:
# Solid archive (better compression)
7z a -tzip archive.zip folder/

# Non-solid (each file compressed separately)
7z a -tzip -ms=off archive.zip folder/
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:
# Create archive
7z a -tzip archive.zip folder/

# Test archive integrity
7z t archive.zip

# List contents
7z l archive.zip

Advanced Topics

Configure web server compression:Nginx:
gzip on;
gzip_comp_level 6;
gzip_types text/plain text/css application/json application/javascript;
Apache:
<IfModule mod_deflate.c>
  AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css
  DeflateCompressionLevel 6
</IfModule>
Pre-compress static files for faster serving:
# Compress all CSS/JS files
for file in *.css *.js; do
  7z a -tgzip -mx=9 "${file}.gz" "$file"
done
Configure server to serve pre-compressed versions.
Deflate stream structure:
Stream:
  Block 1:
    Block header (3 bits):
      BFINAL (1 bit): Last block flag
      BTYPE (2 bits): 00=stored, 01=fixed Huffman, 10=dynamic Huffman
    [Block data]
  Block 2:
    ...
Each block can use different compression strategies.

Troubleshooting

If Deflate compression is ineffective:
  1. Check if data is already compressed
    file suspicious.dat  # Check file type
    
  2. Try higher compression level
    7z a -tzip -mx=9 archive.zip data/
    
  3. Consider LZMA2 for better ratio
    7z a archive.7z data/  # Uses LZMA2 by default
    
If ZIP archives don’t open on other systems:
  1. Use standard ZIP format
    7z a -tzip -ms=off archive.zip files/
    
  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
    unzip -t archive.zip
    7z t archive.zip
    

See Also

Build docs developers (and LLMs) love