Two mechanisms, kept apart: a lossless re-deflate that changes no pixel, and a palette reduction that changes many. The dimensions stay as they are either way.
Lossless means lossless here
PNG stores rows of pixels, each row optionally predicted from the row above or the pixel to the left, and the whole thing deflated. Two files can hold identical pixels and differ by half their size depending on which filter each row picked and how much effort the deflate stage spent.
A browser writing a PNG is optimising for speed: one filter strategy, one deflate pass, done. The lossless pass here works in two stages. The in-page encoder writes the picture under more than one row filter and keeps the shortest; then OxiPNG — the desktop optimiser, built for the browser and fetched from this site the first time it is needed — searches the filters and deflate settings harder still, and the smaller of the two files is kept. Effort (Fast, Balanced, Thorough) sets how hard OxiPNG looks. On a file straight out of a screenshot tool or a canvas the saving is often substantial. On a file that has already been through an optimiser it is close to nothing, and the result says so.
What palette reduction does to a photograph
The other mechanism is not lossless and does not pretend to be. Every pixel is remapped to the nearest colour in a palette of the size you allow, with dithering to hide the seams. A 24-bit image has room for about sixteen million colours; a 256-entry palette has room for 256.
- Screenshots, UI captures, diagrams, logos and line art: usually indistinguishable at 64 to 128 colours, and much smaller. This is the case PNG was built for.
- Gradients, glows and soft shadows: banding appears as the palette shrinks, and dithering trades it for visible noise.
- Photographs: a palette is the wrong tool. If the picture is a photograph, a JPEG at a sensible quality will be smaller and look better than any palette size that keeps it recognisable.
Bit depth, and the 16-bit case
A 16-bit-per-channel PNG carries more precision than a screen can show and more than this page keeps: it is decoded to 8 bits per channel on the way in, and what leaves is 8-bit. For anything headed for a screen or an upload form that is invisible. For a scientific or a print master it is a real loss, and the right answer is not to run that file through a browser at all.
Interlacing, animation and 16-bit precision do not survive.
An interlaced PNG comes out non-interlaced, an APNG loses every frame but the first, and 16-bit channels come out at 8. Each of those is a decision made by the decode-and-re-encode route this page takes, and none of them can be switched off here.
Questions people arrive with
Is the lossless pass really lossless?
Why does my screenshot shrink so much and my photograph barely at all?
How many colours should I allow?
Will transparency survive?
My PNG came back bigger. Why?
Elsewhere on this site
- Compress a JPEGFor photographs, where a quality setting will always beat a palette.
- Compress to a size in KBThe search runs the lossless pass first, so a PNG that fits under the cap untouched stays untouched.
- Upload limits on Indian exam portalsSignature scans are usually PNG, and usually the field with the tightest cap on the form.
