You zip a folder of documents and the archive is smaller than the folder. You save a photo and the copy takes up a fraction of the space. Nothing was thrown in the trash, yet the file shrank. How can the same information fit in less room?
This guide explains what data compression is, where the savings come from and how to measure them. By the end you will be able to tell the two main types apart, work out a compression ratio by hand and see why some files refuse to shrink.
The same message in fewer bits
Computers store everything as bits, each one a 0 or a 1, and group them into bytes of 8 bits. Data compression means writing the same information with fewer bits. A compressor turns the original data into a shorter form, and a decompressor turns that form back into the original. One university algorithms course draws it exactly that way: a bitstream B becomes a compressed version C(B), and expanding C(B) gives B again.
This works because real data is not random. In his 1948 paper, Claude Shannon pointed out that English has statistical structure: the letter E occurs more often than Q. He noted that telegraphy already used the shortest symbol, a dot, for the most common letter. He also estimated that ordinary English is roughly 50% redundant, meaning half of what people write is fixed by the structure of the language and half is chosen freely.
Compression is the craft of finding the predictable part and writing it more briefly.
Three ways the bits get shorter
Most methods lean on one of a few ideas. The first three keep every detail. The fourth drops some.
| Idea | What it exploits | Plain example |
|---|---|---|
| Runs | The same value repeated in a row | Store "15 zeros" instead of fifteen 0s |
| Frequent symbols | Some symbols appear far more often than others | Give the common ones the shortest codes |
| Repeated phrases | The same sequence shows up again later | Point back to the earlier copy |
| Dropped detail | Differences a viewer or listener will not miss | Store an approximation |
The run idea has a classic small example from a university algorithms course. A line of 40 bits made of 15 zeros, 7 ones, 7 zeros and 11 ones can be stored as four counts of 4 bits each: 15, 7, 7 and 11. That is 16 bits instead of 40.
Real formats can stack several ideas. The DEFLATE format behind ZIP, gzip and PNG combines pointers to earlier copies with shorter codes for frequent symbols, a pairing the DEFLATE guide walks through. The first ideas get their own guides too: Huffman coding handles frequent symbols, and repeated patterns covers runs and repeated phrases.
Lossless and lossy: what comes back
The FLAC specification defines the two families in one line each. Lossless compression means decompressing returns exactly the original data. Lossy compression removes or approximates information to save even more space, so decompressing returns an approximation.
Both are everywhere. PNG is lossless. JPEG's main process, based on the discrete cosine transform, is lossy. Text, programs and spreadsheets need the lossless kind, since a changed bit can change their meaning. Photos, music and video can use the lossy kind, which discards detail a viewer or listener may not miss. The full comparison is in lossless vs. lossy compression.
Measuring what you saved
Three numbers describe the result. Each one uses the original size and the compressed size:
- Ratio:
original ÷ compressed - Percent saved:
(1 − compressed ÷ original) × 100 - Space saved:
original − compressed
Worked example. Example: a 10 MB file compresses to 2 MB. Ratio: 10 ÷ 2 = 5, written 5:1. Percent saved: (1 − 2 ÷ 10) × 100 = 80%. Space saved: 10 − 2 = 8 MB. In this guide, MB means 1,000,000 bytes.
The compression ratio calculator does this arithmetic for any two sizes. A ratio of 1:1 means nothing changed, and a ratio below 1:1 means the "compressed" file ended up larger than the original. The meaning of each number is explained further in compression ratio explained.
How much should you expect? It depends on the data and the method. The 1996 DEFLATE specification says English text usually compresses by a factor of 2.5 to 3 with that format. Example: a 1,000,000-byte text file at those two factors becomes 400,000 bytes (60% saved) or about 333,333 bytes (66.7% saved). That is a statement about one format and one kind of data, not a promise for your files.
A limit no method can beat
No lossless method can shrink every possible file. The DEFLATE specification puts it plainly: a simple counting argument shows that no lossless compression algorithm can compress every possible input. If one could, you could compress its output again and again until nothing was left.
The practical result is that files with no predictable pattern barely shrink. Why that happens, and how to spot such files, is covered in why some files barely shrink.
Common mistakes
- Believing compression always deletes something. Only lossy methods discard detail. A lossless method gives back every bit, which is why it is safe for documents and code.
- Expecting every file to get smaller. Some inputs stay the same size or grow slightly. Check the result before assuming a gain.
- Compressing the same file again and again. The first pass removes the predictable parts. The counting argument shows a second pass cannot keep winning.
- Confusing compression with resizing. Cutting an image's width and height removes pixels. Compression writes the same pixels in fewer bits.
- Mixing up two meanings of "compressor". In audio production the word names a tool that evens out loud and quiet. See data compression vs. audio compressors.
FAQ
Is data compression the same as zipping a file?
Zipping is one way to apply it. The ZIP format lists many compression methods, including one called "stored," where the file is copied in without any compression. So a ZIP archive can hold compressed files, uncompressed files or a mix.
Does lossless compression reduce quality?
No. By definition the decompressed data matches the original exactly, bit for bit. Quality can only change with a lossy method.
What is the difference between ratio and percent saved?
Ratio compares the two sizes as a multiple, such as 5:1. Percent saved says how much of the original disappeared, such as 80%. The same result can be written either way.
Why do some files barely shrink?
Their bits already look unpredictable, so there is little pattern for a method to use. Files that were compressed once are a common case.
Sources
- Bell System Technical Journal (reprint hosted by Harvard University), A Mathematical Theory of Communication, C. E. Shannon, 1948. Accessed November 6, 2026.
- Princeton University, Sedgewick and Wayne, 5.5 Data Compression (Algorithms lecture slides). Accessed November 6, 2026.
- IETF, RFC 1951: DEFLATE Compressed Data Format Specification version 1.3. Accessed November 6, 2026.
- IETF, RFC 9639: Free Lossless Audio Codec (FLAC). Accessed November 6, 2026.
- PKWARE, APPNOTE.TXT: .ZIP File Format Specification, version 6.3.10. Accessed November 6, 2026.
- W3C, Portable Network Graphics (PNG) Specification (Third Edition). Accessed November 6, 2026.
- ITU-T (copy hosted by W3C), Recommendation T.81: Digital compression and coding of continuous-tone still images. Accessed November 6, 2026.



