What is lossless compression?

Lossless compression shrinks a file in a way that can be fully reversed, so decoding returns exactly the original pixel data with no quality loss.

By · Updated

Want the full walkthrough? Read: Why is my PNG file so large? →

Explained in more detail

Lossless compression finds redundancy in data and stores it more compactly, without throwing anything away. Decode the file and every pixel is bit-for-bit identical to what was encoded. Zip files work the same way for documents.

Images are good candidates because neighbouring pixels are often similar or identical. PNG first applies a filter to each row that predicts each pixel from its neighbours and stores only the difference, which turns smooth areas into long runs of near-zero values. It then compresses the filtered bytes with DEFLATE. Flat graphics, screenshots and logos compress very well this way. Photographs, full of fine noise, compress far less.

Lossless WebP uses a separate set of techniques from lossy WebP (spatial prediction, color transforms, a color cache and LZ77-style entropy coding), and AVIF can also be encoded losslessly. GIF is lossless for the pixels it stores, but each frame is limited to a 256-color palette, so converting a photo to GIF already loses information before compression starts.

The key practical point is that a lossless format never degrades. You can open and re-save a PNG a hundred times and the pixels stay the same. That makes it the right choice for source assets, logos, screenshots and anything you will edit again.

The cost is file size. For photographs, lossy formats are much smaller.

Related terms

Try it in Triim

Further reading

Sources

Part of the Triim image terms glossary, by Rocco Bombardieri.