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.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/ip7z/7zip/llms.txt
Use this file to discover all available pages before exploring further.
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
Algorithm Overview
Deflate combines two compression techniques:LZ77 Dictionary Compression
LZ77 Dictionary 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
Huffman Coding
Huffman Coding
- 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
Compression Levels
Deflate supports 10 compression levels (0-9):| Level | Strategy | Speed | Compression | Use Case |
|---|---|---|---|---|
| 0 | Store only | Fastest | None | Already compressed data |
| 1 | Fast | Very fast | Minimal | Quick compression |
| 2-3 | Fast | Fast | Fair | Balanced speed/ratio |
| 4-5 | Medium | Medium | Good | Default usage |
| 6 | Default | Medium | Good | Standard (ZIP default) |
| 7-8 | Slow | Slow | Better | Maximum compression |
| 9 | Maximum | Slowest | Best | Archive distribution |
Level 0: Store Only
Level 0: Store Only
Level 1-3: Fast Compression
Level 1-3: Fast Compression
- Limited match searching
- Smaller hash tables
- Faster encoding
Level 6: Default
Level 6: Default
- Good balance of speed and ratio
- Default for most ZIP tools
- Moderate memory usage
Level 9: Maximum Compression
Level 9: Maximum Compression
- Exhaustive match searching
- Larger hash tables
- More CPU time per byte
Memory Requirements
Compression
Deflate compression memory usage:| Level | Memory (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 |
Decompression
Deflate decompression memory usage:Performance Characteristics
- Level 1: ~50-80 MB/s
- Level 6: ~15-25 MB/s
- Level 9: ~5-10 MB/s
- All levels: ~200-400 MB/s
- Text files: 25-40% of original size
- Executable files: 40-60% of original size
- Multimedia files: 95-100% of original size (minimal compression)
Deflate vs Deflate64
Deflate64 (Enhanced Deflate) is an improved version:| Feature | Deflate | Deflate64 |
|---|---|---|
| Method ID | 04 01 08 | 04 01 09 |
| Window Size | 32 KB | 64 KB |
| Match Length | Up to 258 bytes | Up to 65,536 bytes |
| Compression | Good | ~5-10% better |
| Speed | Fast | Slightly slower |
| Compatibility | Universal | Limited (requires Deflate64 decoder) |
Compression Ratio Comparison
Text Files (Source Code, Logs)
Text Files (Source Code, Logs)
| Method | Compression Ratio | Speed |
|---|---|---|
| PPMd | 100% (best) | Very Slow |
| LZMA2 | 110-120% | Slow |
| BZip2 | 120-130% | Medium |
| Deflate | 140-160% | Fast |
Binary Executables
Binary Executables
| Method | Compression Ratio | Speed |
|---|---|---|
| LZMA2 + BCJ | 100% (best) | Slow |
| BZip2 | 130-150% | Medium |
| Deflate | 150-180% | Fast |
Web Content (HTML, CSS, JS)
Web Content (HTML, CSS, JS)
| Method | Compression Ratio | Use Case |
|---|---|---|
| Deflate (gzip) | 100% (standard) | HTTP compression |
| Brotli | 80-90% | Modern browsers |
Command Line Usage
Deflate File Formats
Deflate is used in multiple file formats:ZIP Archives
ZIP Archives
Gzip (.gz)
Gzip (.gz)
tar.gz or .tgzTar.gz Archives
Tar.gz Archives
PNG Images
PNG Images
HTTP Compression
HTTP Compression
Use Cases
When to Use Deflate
When to Use Deflate
- 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
When NOT to Use Deflate
When NOT to Use Deflate
- 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
| Feature | Deflate | LZMA2 | BZip2 | PPMd |
|---|---|---|---|---|
| Method ID | 04 01 08 | 21 | 04 02 02 | 03 04 01 |
| Compression Ratio | Fair (5/10) | Excellent (9/10) | Good (7/10) | Excellent (10/10) |
| Compression Speed | Fast (7/10) | Slow (3/10) | Medium (5/10) | Very Slow (2/10) |
| Decompression Speed | Very 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 Size | 32 KB | Up to 1.5 GB | 900 KB | Variable |
| Multithreading | No | Yes | No | No |
| Streaming | Yes | Yes | Yes | Yes |
| Compatibility | Universal | Limited | Wide | Limited |
| Year Introduced | 1993 | 2009 | 1996 | 2001 |
- Universal compatibility (every platform, every language)
- Very fast decompression (10-20x faster than LZMA)
- Minimal memory (usable on any device)
- Proven reliability (30+ years of widespread use)
Best Practices
Level Selection
Level Selection
- Level 1: Temporary files, network transmission
- Level 6: General-purpose ZIP archives
- Level 9: Archives for distribution, static web assets
ZIP vs 7z Format
ZIP vs 7z Format
- Need compatibility with all systems
- Recipients may not have 7-Zip installed
- Fast decompression is priority
- Need maximum compression (LZMA2)
- All users have 7-Zip or compatible tools
- Archival storage (size matters more than compatibility)
Solid vs Non-Solid with Deflate
Solid vs Non-Solid with Deflate
Testing and Verification
Testing and Verification
Advanced Topics
Deflate in HTTP Compression
Deflate in HTTP Compression
Pre-compression for Static Assets
Pre-compression for Static Assets
Deflate Stream Format
Deflate Stream Format
Troubleshooting
Poor Compression Ratio
Poor Compression Ratio
-
Check if data is already compressed
-
Try higher compression level
-
Consider LZMA2 for better ratio
Compatibility Issues
Compatibility Issues
-
Use standard ZIP format
-
Avoid advanced features
- Don’t use solid mode for ZIP
- Don’t use encryption (or use ZipCrypto)
- Don’t use Deflate64
-
Test with multiple tools
See Also
- LZMA2 Compression - Better compression ratio
- BZip2 Compression - Balanced performance
- Compression Methods Overview - Compare all methods
- External: RFC 1951 (Deflate specification), zlib library documentation
- Tools: gzip, pigz (parallel gzip), zopfli (optimized Deflate)