Calculate compression ratio and space savings between original and compressed file sizes.
Compression ratio (original:compressed) and space-saved percentage describe the same result two ways. How much a file actually compresses depends heavily on its entropy: plain text, logs and source code compress very well (~70% smaller) because of high redundancy; generic binaries and database dumps compress moderately (~20%); and already-compressed media formats like JPEG, MP4 and MP3 barely shrink further (~5%) because their encoders already removed most redundancy — recompressing them mostly wastes CPU time.
Compression ratio and space saved
ratio = original / compressed; space_saved% = (1 − compressed/original) × 100
JPEG, MP4 and MP3 already apply strong lossy/entropy compression internally, so there's little statistical redundancy left for gzip's algorithm to exploit. Compressing an already-compressed file typically saves only a few percent and can occasionally even increase size slightly due to format overhead.
Text-heavy logs typically compress 4:1 to 10:1 (70-90% space saved) with gzip, and even better with algorithms like zstd or xz at higher settings, because of repeated timestamps, field names and common message patterns.
Not necessarily — higher-ratio algorithms (like xz -9) trade significantly more CPU time and memory for modest extra savings over faster options (like gzip or zstd). For frequently-accessed data, a faster algorithm with a slightly lower ratio is often the better overall trade-off.