Calculate the compression ratio and space savings between original and compressed data sizes.
The compression ratio expresses how many times smaller a compressed file is compared to its original, calculated by dividing the original size by the compressed size — a ratio of 4:1 means the compressed file is a quarter of the original. Space savings, expressed as a percentage, is derived from the ratio as one minus its reciprocal, giving an intuitive figure for how much storage or bandwidth was reclaimed.
Compression ratio and savings
ratio = original_size / compressed_size; savings = (1 − 1/ratio) × 100%
A 4:1 ratio means the original file is four times larger than the compressed version — equivalently, the compressed file occupies 25% of the original's storage or transfer footprint, a 75% space saving.
Compression algorithms exploit redundancy and predictable patterns in data. Text and uncompressed formats (BMP, WAV, raw logs) usually compress well because they contain repeated structures, while already-compressed formats (JPEG, MP4, ZIP) compress poorly because their redundancy has already been removed.
Not necessarily — very high ratios from lossy compression can degrade quality (images, audio, video), and higher-ratio algorithms often demand more CPU time to compress and decompress, so the right choice balances size, quality, and processing cost for the use case.