Lossless vs lossy compression: what you get back, and what you give away
One kind of compression folds a file so you can unfold the exact original. The other leaves something behind on purpose so the file will fit.
The one-question test
After you unpack, do you have the exact original bytes? If yes, it was lossless. If the picture still looks fine but a checksum no longer matches, or a faint sparkle in the sky is gone, it was lossy. The hash generator is a strict judge: two files with the same SHA-256 are the same bytes; a JPEG saved a second time at “quality 80” almost never matches the first file, even when your eye cannot tell them apart.
How lossless compression works
A lossless packer looks for repetition and writes a pointer instead of copying the bytes again. “LA LA LA LA” becomes “LA, four times”. A letter that keeps using the word “the” puts “the” in a short dictionary and writes a tiny code each time it comes back. ZIP and gzip both use Deflate, which does this for phrases of bytes, not only whole words. PNG uses Deflate too, after a filter that turns flat colour into long runs of zeros. FLAC does the same idea for audio.
It only helps when there is a pattern to fold. A file of random bytes, an encrypted file, or a file that has already been packed, looks like noise. The recipe is then roughly as long as the original, plus a small header — so the result can even grow a little.
How lossy compression works
A lossy packer asks a different question: what can we throw away before anyone notices? A camera JPEG discards tiny colour wobbles and high-frequency sparkle your eye is bad at seeing, then losslessly packs what remains. An MP3 keeps the tune and skips faint overtones that would be masked by louder notes. A video call paints bigger blocks on a slow connection so the face still fits the pipe.
That discarded detail is gone for good. Opening a JPEG and saving it again at a lower quality throws more away (generation loss). Turning a JPEG into a PNG does not bring the sparkle back: you only losslessly pack the already-simplified picture, and the file often gets larger.
Common formats
| Format | Kind | What it is for |
|---|---|---|
| ZIP, gzip, 7z, brotli | Lossless | Documents, code, logs, bundling files |
| PNG, lossless WebP, TIFF (lossless) | Lossless | Screenshots, logos, graphics with flat colour or sharp text |
| FLAC, ALAC, WAV (uncompressed) | Lossless or raw | Audio you want back bit-for-bit |
| JPEG, everyday HEIC, lossy WebP | Lossy | Camera photos |
| MP3, AAC, Opus | Lossy | Music and speech where a smaller file matters more than a perfect waveform |
| H.264, H.265, VP9, AV1 | Lossy | Video |
Which should you pick?
- Keep every byte (invoices, source code, a photo you may want to print or edit later): lossless, or do not compress at all.
- Send or publish a photo: a deliberate lossy pass — resize so the long side matches the screen (1920 px is a safe all-rounder) and save as JPEG quality 75–80 or WebP. The in-browser image compressor does that on your device, so the picture is never uploaded, and hidden GPS tags are dropped.
- A screenshot with text: PNG (lossless). JPEG makes letters look muddy around the edges.
- A folder of already-taken camera photos: do not expect ZIP to shrink them. Shrink the pictures, then zip the results if you want one file. See why zipping photos does not make them smaller.
See it happen
For the lossy side, What happens when you squish a video too much? squishes a real little picture in your browser, from lossless packing to a blocky splat, and shows which details fall out first.
The short interactive lesson Why does zipping photos barely make them smaller? lets you guess how small four suitcase items will get — a repeating chorus, an ordinary letter, a camera JPEG and TV snow — then packs them and shows the sizes. A second step unpacks a tiny face two ways: folded carefully (lossless, every pixel comes back) or with the thick jumper left behind (lossy, the sparkle in the eyes is gone).
Related
Why GIFs are so much bigger than MP4 · Compress a video to a target size · What lossy damage looks like in a photo (JPEG artefacts) · Why a ZIP can be larger than the originals · gzip vs ZIP · CRC failed / unexpected end of archive · Why zipping photos barely makes them smaller (interactive lesson) · Why zipping photos does not make them smaller · Compress many photos at once · Compress an image without uploading it · Image compressor
Questions
What is the difference between lossless and lossy compression?
Lossless rebuilds the exact original bytes when you unpack (ZIP, PNG, FLAC, gzip). Lossy throws away detail on purpose so the file can be much smaller (JPEG, MP3, H.264) and you cannot get that detail back.
Is ZIP lossless?
Yes. Unzipping gives back the same bytes you put in. That is also why ZIP cannot make an already-compressed JPEG much smaller: there is no pattern left to fold, and it refuses to throw detail away.
Is JPEG lossy?
Yes. A camera JPEG has already discarded fine detail and packed the rest. Saving the same picture again at a lower quality throws more away. Converting it to PNG does not restore what was discarded.
Can I turn a JPEG back into the original lossless photo?
No. The discarded detail is not stored anywhere in the file. You would need the original camera file (often a RAW, or the first JPEG the camera wrote) from before later re-saves.
Is PNG always better quality than JPEG?
PNG is lossless, so it keeps every pixel of whatever you give it. If you start from a JPEG, the PNG is a perfect copy of that already-lossy picture, usually at a larger file size. For camera photos, a fresh JPEG or WebP at a sensible quality is the smaller choice; for screenshots and sharp text, PNG wins.
Published · updated .