Standard Compression Levels (1-19)
The library supports regular compression levels from 1 up to 22. Lower levels provide faster compression at the cost of compression ratio, while higher levels achieve better compression ratios at the cost of speed.Default Compression Level
The default compression level is 3 (ZSTD_CLEVEL_DEFAULT).
Setting Compression Levels
Simple API
examples/simple_compression.c:28
Advanced API
examples/streaming_compression.c:43
Fast Modes (Negative Levels)
Zstandard also offers negative compression levels, which extend the range of speed vs. ratio preferences. These fast modes prioritize speed over compression ratio.Using Fast Modes
Fast modes are specified with--fast=# on the command line:
The lower the level (more negative), the faster the speed at the cost of compression ratio.
Performance Characteristics
Benchmark results on a Core i7-9700K CPU @ 4.9GHz using the Silesia compression corpus:| Compressor | Ratio | Compression | Decompression |
|---|---|---|---|
| zstd 1.5.7 -1 | 2.896 | 510 MB/s | 1550 MB/s |
| zstd 1.5.7 —fast=1 | 2.439 | 545 MB/s | 1850 MB/s |
| zstd 1.5.7 —fast=4 | 2.146 | 665 MB/s | 2050 MB/s |
README.md:44-49
Ultra Modes (20-22)
Levels 20-22 are labeled as--ultra modes and require explicit enabling. These levels provide maximum compression but require significantly more memory.
Enabling Ultra Modes
On the command line:--ultra flag is required to enable levels beyond 19, up to 22.
From programs/README.md:196
Compression Level Bounds
You can query the valid range of compression levels:Speed vs Ratio Trade-offs
Zstandard’s compression levels offer configurable speed vs compression trade-offs in small increments. Key characteristics:- Decompression speed is preserved and remains roughly the same at all settings
- Compression speed decreases as the level increases
- Compression ratio improves as the level increases
Environment Variables
The default compression level can be overridden using theZSTD_CLEVEL environment variable:
programs/README.md:264-266
Compression Strategies
Higher compression levels use more complex strategies:lib/zstd.h:336-347
The higher the value of the selected strategy, the more complex it is, resulting in stronger and slower compression.