How lossless image compression actually works
Why a smaller file can be pixel-for-pixel identical to the original — and the prediction, modeling and entropy-coding tricks that make it happen.
Why a smaller file can be pixel-for-pixel identical to the original — and the prediction, modeling and entropy-coding tricks that make it happen.
"Lossless" sounds like a contradiction: how can a file get smaller without throwing anything away? The trick is that an image is full of redundancy, and compression is the art of describing the same pixels with fewer bits. Decode it and you get back every original value, exactly — bit for bit.
Lossy formats like JPEG discard information your eye is unlikely to miss. Lossless compression discards nothing: the decoded image is identical to the input. That's why it's the right choice for screenshots, line art, logos, UI assets and archival masters — anything where a single shifted pixel would be a bug, not a rounding error.
Raw pixels are wasteful because neighbors are highly correlated — the pixel to your left is usually a great guess for the current one. Lossless codecs predict each pixel from its neighbors and store only the small error (the residual). PNG calls these filters (Sub, Up, Average, Paeth); the better the prediction, the closer the residuals cluster around zero, and zeros compress beautifully.
Once the data is mostly small, repetitive residuals, an entropy coder assigns short codes to common values and long codes to rare ones. PNG uses DEFLATE (LZ77 + Huffman); modern codecs like WebP lossless and JPEG XL use context modeling with arithmetic or ANS coding, which squeezes closer to the theoretical limit. The format changes, but the idea is the same: spend fewer bits on what's predictable.
This is why two lossless PNGs of the same image can differ wildly in size: the pixels are identical, but the encoder worked harder to describe them. oxipng searches filter strategies and recompresses; zopfli is a much slower DEFLATE that often shaves a few more percent; WebP and JPEG XL bring smarter models entirely. None of them touch a pixel.
# Lossless, maximum effort — identical pixels, smaller file imageforge logo.png --lossless --effort max imageforge ui-export.png --convert webp --lossless
Lossless has a floor. Photographs of real scenes carry genuine high-frequency detail (sensor noise, fine texture) that simply doesn't predict well, so lossless gains there are modest — that's when lossy formats earn their place. For flat, synthetic or text-heavy images, though, lossless routinely cuts 30–70% with zero quality cost. The skill is knowing which bucket your image falls into.
ImageForge runs oxipng, zopfli and modern lossless encoders for you — locally.
Join the waitlist