PixSqueeze

Fast · Private · High-Efficiency
Explainer

How image compression actually works

Most people use a quality slider without knowing what it does. Understanding it takes about ten minutes and makes every subsequent decision obvious.

Close-up of visible blocking artifacts caused by heavy JPEG compression
Photo: Exey Panteleev / Wikimedia Commons, CC BY 2.0

Two entirely different things

Lossless compression1 finds redundancy and describes it more efficiently. Nothing is discarded — decompress the file and you get back exactly what went in, byte for byte. PNG works this way2, as does ZIP.

Lossy compression3 throws information away permanently, choosing things human vision is bad at noticing. You cannot get the original back. JPEG, WebP and AVIF all work this way — compared here.

This is why a quality slider exists for JPEG but not for PNG. With lossless there is nothing to trade — there is one correct answer and the encoder either finds a smaller representation or it does not.

What lossy compression discards

Human vision has known weaknesses, and lossy formats exploit them systematically.

We are far more sensitive to brightness than to colour. So the encoder keeps luminance detail at full resolution and stores colour information at half resolution or less — chroma subsampling4. You genuinely cannot see the difference in a photograph, and it removes a large fraction of the data immediately.

We are also poor at seeing fine detail in busy areas. The encoder breaks the image into blocks, converts each to frequency information with a discrete cosine transform5, and discards the high-frequency components that describe the smallest variations. The quality slider is essentially a dial on how much of that fine detail to throw away.

Why artefacts look the way they do

Compression artefacts are not random noise; they are the shape of the algorithm showing through.

Blocking — visible squares in skies and gradients — happens when the encoder has discarded so much that adjacent blocks no longer blend. Ringing — halos around sharp edges and text — happens because a hard edge needs high-frequency information to describe, and that is exactly what was removed.

This is why text and line art suffer so badly under JPEG while photographs cope well. A photograph has soft, continuous variation. Text is nothing but hard edges.

Generation loss is real

Every time you save a lossy image, information is discarded. Save it again and the encoder is now working on the already-damaged version, treating the previous pass's artefacts as detail worth preserving.

Do this repeatedly and the image visibly degrades — this is generation loss6, the same phenomenon as photocopying a photocopy. It is why you should always work from the largest, cleanest original you have rather than from something already exported for another purpose.

One compression pass from an original is fine and invisible. Five passes is not.

What this means for your settings

  • Photographs — lossy, quality 70–80. The saving is enormous and the loss is invisible.
  • Text, screenshots, line art — lossless, or lossy at high quality. These are the worst case for lossy formats.
  • Anything you will edit again — keep a lossless master and export lossy copies.
  • Already-compressed files — recompressing gains little and costs quality. Go back to the source.

Why the same settings give different sizes

Two photos exported at identical settings can differ several-fold in file size, which looks like a bug and is actually the compression working correctly.

Lossy compression spends bytes in proportion to how much detail there is. A photograph of foliage, gravel or a crowd is dense with high-frequency variation, and describing it takes data. A studio portrait against a plain backdrop is mostly smooth gradient, which compresses to very little.

This is also why quality settings behave differently per image. Smooth areas show blocking artefacts early, because there is no visual noise to hide them behind — skies and skin are the classic tell. Busy images can absorb far more compression before anything is visible. Which quality setting to use goes into where the usable range sits.

What is actually being discarded

The transform stage sorts image information by frequency: broad shapes and gradual gradients at one end, fine texture and hard edges at the other. Quantization then stores the high-frequency end more coarsely, because human vision is measurably less sensitive to it.

Colour gets similar treatment. Brightness is perceived far more precisely than colour, so chroma is commonly stored at half resolution horizontally and vertically — a technique called chroma subsampling. Four pixels share one colour value while keeping their own brightness. For photographs this is close to invisible.

It is also exactly why compressed text looks wrong. Letterforms are pure high-frequency hard edges, and red text on a white background is the pathological case: high-frequency and heavily dependent on the colour channel being discarded. The lossy/lossless split explains when to avoid this entirely.

Why compressing twice is worse than compressing once

A decoded JPEG is not the original image — it is the original plus the artefacts of the first compression pass. Re-encode that and the second pass has no way to distinguish artefact from detail, so it faithfully preserves the damage and adds its own.

Repeat across a few rounds and quality degrades visibly, a phenomenon known as generation loss. It is why a meme re-saved through a dozen platforms looks the way it does.

The rule that follows is simple and worth being strict about: keep an untouched master and export from it every time. Never edit and re-save the exported copy. A batch workflow builds that in as an invariant.

References

  1. Lossless compressionWikipedia↑
  2. Portable Network Graphics (PNG) Specification (Third Edition)W3C↑
  3. Lossy compressionWikipedia↑
  4. Chroma subsamplingWikipedia↑
  5. Discrete cosine transformWikipedia↑
  6. Generation lossWikipedia↑