Explainer8 min read

PNG compression is lossless, so why does compressing a PNG lose something

Because two different operations share the same button. One rearranges bytes and changes nothing. The other throws away colours, and on the wrong image it is obvious.

PNG is a lossless format. Decode a PNG and you get back exactly the pixels that went in, every time. Yet a PNG compressor can visibly damage a photograph, and people reasonably conclude that either the format or the tool is lying. Neither is. There are two separate things a PNG optimiser can do, and only one of them is lossless.

The lossless half: better packing

A PNG stores rows of pixels compressed with the same general-purpose algorithm as a ZIP file, after a per-row prediction step that turns each pixel into a difference from its neighbours. Long runs of similar colour become long runs of near-zero differences, which pack tightly.

A lossless optimiser tries harder at that step: different prediction filters per row, a more exhaustive search for repeated patterns, and removal of chunks that carry no visual information. The pixels that come back out are bit-for-bit identical. The saving is real but modest, usually a few percent to perhaps a fifth, and it is entirely free of consequences.

The lossy half: fewer colours

The big savings come from somewhere else: reducing how many distinct colours the image is allowed to contain. A full-colour PNG can hold millions. Quantisation picks a palette of a few hundred, maps every original pixel to its nearest palette entry, and stores small indices instead of full colour values. That can cut a file by half or more, and it is not lossless in any sense. The discarded colours are gone.

Whether you notice depends entirely on what the image contains, and the outcome is predictable enough to decide in advance.

Where it works and where it fails

Screenshots, diagrams, logos, icons and charts are made of flat areas of a small number of colours. A palette of 256 covers them completely, the mapping is exact, and the file gets dramatically smaller with no visible change at all. This is the case PNG optimisation was invented for, and it is what compressing a PNG is good at.

Photographs are the opposite. A sky is a smooth gradient across thousands of subtly different blues. Force it into a few hundred and the gradient becomes visible bands. Optimisers hide this with dithering, scattering pixels between two palette entries so the eye averages them, which trades banding for a fine speckle. It looks better than banding, but it also defeats the compressor, because speckle is noise and noise does not pack.

What to do instead

If the image is a photograph, the right answer is almost never a smaller PNG. It is a different format. JPG and WebP were built to discard exactly the detail human vision is least sensitive to, and they will beat any quantised PNG on both size and appearance. Our format benchmark put numbers on that across 46 images. Convert, do not compress: PNG to JPG if the destination is a person, PNG to WebP if it is a web page.

If the image has transparency you need to keep, WebP supports an alpha channel and still compresses photographically. That is usually the best of the available trades.

And keep PNG where it earns its place: screenshots, anything containing text, line art, and any file you intend to edit and re-save repeatedly. Lossless matters most for images that are still being worked on.

One habit covers all of it. Compare the two outputs at full size, side by side, on the screen the image is actually for. Bands and speckle are invisible in a thumbnail and obvious at 100%.

Caveats

  • The size ranges here describe typical behaviour rather than a guarantee. Savings vary with image content more than with any setting, which is the whole point of the article.
  • The measured figures for this site's own encoders, including the PSNR that shows which formats kept the pixels, are in the format benchmark rather than restated here.

Try it on your own files

Most image conversions run in your browser and never leave your device.

Open the converter

Read next

The attachment limit is not the number you were told