AllConvert

File compression explained: ZIP, GZIP, lossy and lossless

Compression makes a file smaller by removing redundancy — patterns and repetition that can be described more briefly than they are stored. There are two fundamentally different ways to do it, and knowing which one you are using explains most of the surprises people run into.

Lossless vs lossy

Lossless compression rebuilds the original file byte for byte. Nothing is thrown away; the data is just packed more efficiently. ZIP, GZIP, PNG and FLAC all work this way, which is why you can compress a spreadsheet, unzip it a year later, and get back exactly what you put in. This is the only kind you can safely use for code, documents, or anything where a single changed byte matters.

Lossy compression takes a different bargain: it permanently discards information it judges you are unlikely to notice. JPG drops fine color detail the eye barely registers; MP3 removes sounds masked by louder ones; video codecs do both. You cannot get the original back, but the files are far smaller than lossless could ever manage. That trade is fine for a holiday photo and a disaster for a legal contract.

How lossless actually finds redundancy

Two ideas do most of the work. First, repeated sequences get replaced by short back-references — instead of storing the word "the" a thousand times, the compressor stores it once and then points back to it. Second, entropy coding gives the most common symbols the shortest codes, the way Morse code spends a single dot on "E" and saves the long sequences for rare letters. Put together, these two steps are essentially the DEFLATE algorithm, and DEFLATE is the engine inside ZIP, GZIP and PNG alike.

That shared engine is worth remembering. A PNG is really just your pixel data run through the same kind of compression a ZIP would apply, which is why zipping a folder of PNGs barely shrinks it — the images are already compressed.

ZIP and GZIP are not the same job

ZIP is an archive format. It bundles many files into one container and compresses each of them separately, keeping a small directory at the end. Because each entry stands on its own, you can pull one file out of a large ZIP without decompressing the rest. That makes ZIP the natural choice when you want to hand someone a folder as a single download.

GZIP compresses a single stream of bytes and knows nothing about files or folders. That sounds like a limitation, and it is why on Unix systems you constantly see .tar.gz: tar does the job of gluing many files into one stream, and gzip compresses that stream. GZIP's real home is the web — servers gzip HTML, CSS and JavaScript on the fly before sending them, which is one of the cheapest speed wins a site can get.

Why compressing a JPG or MP4 barely helps

A common surprise: you zip a folder of videos to email it and the ZIP is almost the same size as the originals, sometimes a hair larger. Nothing is broken. MP4, JPG and PNG are already compressed, so there is almost no redundancy left for DEFLATE to find, and the ZIP container adds a little overhead of its own. Compression works on redundancy, and these formats have already spent it.

The files that shrink dramatically are the ones full of repetition: plain text, CSV exports, log files, source code, XML and JSON. A multi-megabyte log can collapse to a fraction of its size because it repeats the same timestamps and phrases over and over.

Generation loss, and why the original matters

With lossy formats, every re-save compounds the damage. Open a JPG, edit it, save it again, and you are compressing an already-compressed image — the artifacts from the first pass get baked in and a fresh set is added on top. Do that a few times and the picture visibly degrades. The rule that follows is simple: always work from the highest-quality original you have, and export to a lossy format once, at the end.

Newer algorithms

DEFLATE is old and everywhere, but it is no longer the best. Zstandard (zstd) compresses faster and tighter and now shows up in everything from file systems to package managers. Brotli, developed at Google, often beats gzip for web content and is widely supported by browsers, so many sites now serve Brotli-compressed pages when the browser accepts them. You rarely choose these by hand — the tools pick them — but they are why the web keeps getting a little faster.

Doing it here

The main converter can bundle any file into a ZIP or compress it with GZIP, and extract both, entirely in your browser. If your goal is smaller images specifically rather than a smaller archive, that is a different tool — the image compressor re-encodes photos at a chosen quality, and the image formats guide covers which format to pick.