Micro Tool Yard logo
Tools

Blog

The Two Totally Different Ways 'Image Compression' Can Work

Lossy and lossless compression aren't two settings on the same dial — they're different mathematical strategies with different guarantees.

"Compress this image" sounds like a single operation with a single dial, but it's really two unrelated strategies that happen to share a name. One throws away information the human eye is unlikely to miss and never gives it back. The other finds redundancy in the exact data and packs it more efficiently without discarding anything. A quality slider on a compression tool is almost always steering the first kind — and understanding what it's actually doing explains why the same slider behaves so differently on a photo versus a screenshot.

Lossless: finding redundancy, not deleting data

Lossless compression works the same way a ZIP file compresses text: it finds statistical redundancy in the data and encodes it more compactly, in a way that's perfectly reversible. For images, PNG's approach is a good illustration — before general-purpose compression even runs, each row of pixels goes through a filtering step that tries to predict each pixel's value from its neighbors (the pixel to the left, above, or a combination) and stores only the difference from the prediction. If a region of the image is a flat, solid color, that difference is zero for long stretches, which compresses extremely well under DEFLATE. The original pixel values can always be reconstructed exactly, because nothing about them was approximated — only their representation on disk changed.

The catch is that lossless compression's efficiency depends entirely on how much redundancy the image actually contains. A screenshot of a text editor, mostly flat background color with sharp-edged text, has enormous redundancy and compresses dramatically. A photograph of tree leaves in afternoon light, full of fine, mostly-random variation between adjacent pixels, has very little redundancy for a predictive filter to exploit — the compressed file ends up barely smaller than the raw pixel data, no matter how aggressively you run the algorithm, because there's genuinely little repeating structure to find.

Lossy: deciding what the eye won't miss

Lossy compression doesn't try to preserve every pixel value — it tries to preserveperceived quality while discarding whatever contributes least to it. JPG's method, still the reference case most people are familiar with, transforms 8x8 blocks of pixels into frequency components (via a discrete cosine transform) and then quantizes those components — rounds them to a coarser scale — more aggressively for high-frequency detail than for the broad shapes that dominate visual perception. A quality slider controls exactly how coarse that quantization gets: at quality 90, the rounding is gentle and most detail survives; at quality 30, entire ranges of fine detail collapse to the same quantized value and get reconstructed as flat blocks, which is where the telltale blocky artifacts around sharp edges come from.

The key property of lossy compression is that it's a one-way trip: once those frequency components are quantized and discarded, no amount of re-opening and re-saving the file recovers them. This is also why repeatedly re-saving a JPG at lossy settings degrades it further each time — each pass re-quantizes an image that's already lost information from the previous pass, compounding the artifacts rather than just repeating the same rounding.

What a "quality" slider is actually trading

Because lossy and lossless are different mechanisms, a single slider can't meaningfully cover both, which is part of why tools usually separate them: a "lossless optimize" option that strips redundant data and re-encodes more efficiently with no visible change at all, versus a quality percentage that controls how much perceptual detail gets discarded. The size reduction available from lossless optimization alone is usually modest — often 10-30% depending on how inefficiently the original file was encoded — while lossy compression can shrink a file by 80% or more at the cost of some visible quality loss, with the exact tradeoff point depending heavily on the image content and viewing conditions (a heavily compressed image can look fine as a thumbnail and show artifacts clearly at full size).

Picking a strategy for the actual image

The right choice tracks back to the same content distinction that decides format choice more generally: photographs with continuous tone tolerate lossy compression well, because the discarded high-frequency detail is exactly the kind of fine noise that's hard to perceive against gradual color transitions anyway. Screenshots, diagrams, and anything with sharp edges or large flat regions are poor candidates for aggressive lossy compression, since that's precisely where blocky quantization artifacts are most visible, but they're excellent candidates for lossless compression, since flat regions and repeated patterns are exactly what a predictive filter exploits well. A tool that lets you dial quality per image — rather than applying one fixed setting to every upload — is doing the useful part of the job; theCompress Image tool on this site exposes that quality control directly so the tradeoff is a choice you make, not one buried in a fixed default.