Skip to content
Minute Campus.

Everyday computer scienceLesson 091 min

How does a zip file shrink without losing anything?

A zip file does not store a repeat twice. The first time, it writes the text. After that, it writes a short note: go back this far and copy this many characters. Unzipping follows the notes, so nothing is lost. A sentence repeated a hundred times, 4,800 bytes, came out at 84. Random data has nothing to point back to, and came out slightly bigger than it went in.

Remember

Compression works by removing repetition, so already compressed files barely shrink.

Sources

Checked at the source.

Every claim in the lesson was checked against these before it was recorded.

  1. 1DEFLATE Compressed Data Format SpecificationRFC 1951 · read 4 Oct 2026Compressed data holds literals and length-distance pointers to duplicates; no lossless method compresses every input.

Transcript

The lesson, word for word.

Read it at your own pace, or search the page for a term.

A zip file can be a fraction of the original size, and when you open it, every byte comes back. Where did the rest go? Nowhere. It was repetition. Most files repeat themselves: the same words, the same spaces, the same patterns. The zip method does not store a repeat twice. The first time, it writes the text. The next time, it writes a short note instead: go back this far, and copy this many characters. I tried it. One sentence repeated a hundred times, forty-eight hundred bytes, came out at eighty-four. Unzipping follows the notes, so nothing is lost. That is why it is called lossless. It also explains the limit. A file with no repetition gives the method nothing to point back to. The same test on random data came out slightly bigger than it went in. So zipping a photo or a video barely helps. Those formats are already compressed.

Questions? Comment on the lesson on YouTube

New lessons every day.

Follow Minute Campus where you already scroll.