How Image Compression Works: Lossy vs Lossless

Compression sounds like magic — the same picture, but a tenth of the size. It is not magic, though; it is a mix of removing information that repeats and removing information you were never going to notice. Understanding the two families of compression makes it obvious when quality is safe and when it is at risk.
Lossless: squeeze out the redundancy
Lossless compression finds patterns and stores them more efficiently, without discarding anything. If a hundred pixels in a row are the same shade of blue, it records "blue ×100" instead of listing each pixel. Algorithms like Deflate (used by PNG) and the lossless mode of WebP do this with clever dictionaries and prediction. Because nothing is thrown away, you can decompress back to a bit-for-bit identical image — perfect for logos, diagrams and screenshots where every edge must stay crisp.
Deflate itself combines two ideas: LZ77, which replaces a repeated sequence with a short reference back to where it appeared before, and Huffman coding, which gives the most frequent symbols the shortest bit patterns. PNG helps it along by filtering each row first, so a smooth gradient reaches the compressor as a run of near-identical small numbers rather than as unique colours. WebP's lossless mode adds colour transforms and per-block predictors of its own, and typically lands about 25% below PNG on the same image.
Lossy: discard what the eye ignores
Lossy compression goes further by permanently deleting detail the human visual system barely registers. JPEG, for example, splits the image into 8×8 pixel blocks and applies a discrete cosine transform, which separates gradual tone changes from fine detail. It then keeps the important low-frequency information and coarsens or drops the high-frequency parts — our eyes are far more sensitive to brightness and broad shapes than to tiny colour variations. The result is dramatically smaller files, at the cost of detail you usually cannot see.
That sensitivity gap is exploited twice over. Before the transform runs, most encoders store the two colour channels at half width and half height — chroma subsampling — which removes three quarters of the colour data on its own and is almost invisible on a photograph. It is visible on saturated text and thin coloured lines, which is exactly where JPEG looks worst.
The quality setting controls how aggressively this happens. High quality removes only the subtlest detail; low quality removes so much that blocky artifacts appear, especially around sharp edges and in smooth gradients like skies.
What the quality number really does
The quality slider is not a percentage of the image you keep. In JPEG it scales a quantisation table: at quality 100 the divisors are close to 1 and nearly every coefficient survives; at 50 the high-frequency divisors are large enough that most fine detail rounds to zero. The scale is not linear either. Going from 95 to 85 usually halves the file and costs almost nothing you can see, while going from 60 to 50 saves a much smaller fraction and costs a great deal.
In practice 75–85 is the useful band for JPEG and 75–80 for WebP. Above roughly 90 you are mostly storing sensor noise; below about 65 the 8×8 grid starts to show on flat areas and coloured fringes appear along text and hard edges. Encoders also disagree with each other: two tools both set to "quality 80" can produce files 30% apart, so trust the preview and the byte count rather than the number itself.
Why some images compress badly
Not every picture responds the same way. Screenshots, charts and anything containing text are the classic problem: lossy compression spends its budget on smooth tonal change and has nothing useful to do with a black letter on a white field, so it leaves grey fringes around every glyph while still costing more bytes than a lossless PNG would. Film grain and sensor noise are the opposite trouble — that detail is real, random and genuinely incompressible, so a noisy night photo can be twice the size of a clean daylight one at identical settings.
Flat colour and long gradients are easy for lossless compression and surprisingly awkward for lossy. A clear sky has so little variation that coarse quantisation turns it into visible steps, or banding. When you see banding the answer is usually a few more points of quality, or a little dither in the export, not a different format.
Why re-saving lossy images hurts
Because lossy compression is irreversible, each save throws away a little more — open a JPEG, edit it, save again, and you compress already-compressed data. This is generational loss, and it slowly degrades an image. The fix is to keep a lossless master (PNG or the original camera file) and export a fresh lossy copy each time, rather than repeatedly editing the JPEG. Compress once, from the best source you have.
The damage compounds because each pass re-quantises coefficients that were already rounded and re-subsamples colour that was already halved. Crop or rotate the file and the 8×8 grid no longer lines up with the old one, so errors from the previous generation are smeared across new block boundaries. A single re-save at high quality is usually invisible; five or six of them at 80 are not.
The takeaway
Lossless compression is reversible and best for graphics; lossy compression permanently drops imperceptible detail and is best for photos. Always compress from an original, high-quality source. Try both by switching PixelPress between PNG and JPEG/WebP output.
Compress PNG, JPEG and WebP right in your browser.
More guides

PNG vs JPEG vs WebP: Which Format to Use
Each format is good at a different job. Learn what PNG, JPEG and WebP are built for, and a simple rule for picking the right one every time.

How to Compress Images Without Losing Quality
You can cut most of an image's file size while keeping it visually perfect. Here is the practical workflow and the settings that matter.

Why WebP Is Smaller (and When to Use It)
WebP routinely beats JPEG and PNG on size at the same quality. Here's the technical reason — and the handful of cases where you might still avoid it.