Skip to content

How image compression actually works

6 min read Formats Updated July 2026

Compression is the one image operation almost everyone performs and almost nobody understands. The quality slider goes from 0 to 100, the file gets smaller, and somewhere along the way it starts looking bad — but where, and why, is usually left as a mystery.

It is worth understanding, because the relationship between the number and the result is deeply non-linear, and knowing the shape of that curve is the difference between files that are three times larger than they need to be and files that visibly fall apart.

The insight compression is built on

Human vision is not a uniform sensor. We are far more sensitive to changes in brightness than to changes in colour, and far more sensitive to broad shapes than to fine detail within a busy texture. Lossy compression is, fundamentally, a systematic exploitation of those two weaknesses.

The first is exploited by chroma subsampling. A JPEG typically stores brightness at full resolution but colour at half resolution horizontally and vertically — so three quarters of the colour information is discarded before any other compression happens. On a photograph this is essentially invisible. On a sharp red line against white it is not, which is why coloured text in a JPEG looks smeared.

The second is exploited by the frequency transform, and that is where the quality slider actually lives.

What the quality slider does

JPEG divides the image into 8×8 pixel blocks and converts each block from pixel values into frequency coefficients — one describing the block's average brightness, the rest describing progressively finer variation within it.

This transform is reversible and lossless on its own. The loss happens next: each coefficient is divided by a value from a quantisation table and rounded to an integer. High-frequency coefficients get divided by large numbers, so most of them round to zero — and long runs of zeros compress to almost nothing.

The quality setting scales that table. At quality 100 the divisors are small and little is lost. At quality 50 they are large and most fine detail rounds away. This is why the scale is non-linear: you are not removing a fixed fraction of information per point, you are scaling a table whose effect compounds.

It also explains where artefacts come from. Because the transform operates on independent 8×8 blocks, heavy quantisation makes adjacent blocks resolve to slightly different averages — visible as blockiness in smooth gradients like skies. And because a sharp edge requires many high-frequency coefficients to reconstruct, discarding them produces ringing around the edge: the faint halo of speckle known as mosquito noise.

Where the useful range is

For typical photographic content, the practical map looks like this:

  • 100 to 90: essentially no visible difference from the original, but a large file. Wasteful for anything web-facing.
  • 90 to 80: still visually indistinguishable on most photographs, at roughly half the file size of 100. This is where most images should sit.
  • 80 to 70: fine for most photographs; slight softening in fine texture. Good for thumbnails and secondary images.
  • 70 to 60: artefacts become visible in skies, skin tones and around sharp edges.
  • Below 60: obvious blockiness and ringing. Only appropriate when file size dominates everything else.

Why content matters more than the number

The bands above assume photographic content. Different material behaves very differently at the same setting.

A photograph of foliage, gravel or fabric hides artefacts extremely well, because the noise introduced by compression is masked by the texture already present. These images can go lower than you would expect.

A photograph containing large smooth gradients — a clear sky, a studio backdrop, out-of-focus background — shows banding early, because there is no texture to hide the block boundaries. These need a higher setting than their apparent simplicity suggests.

Images with sharp edges — screenshots, text, illustrations, logos — are the worst case, and often should not be lossy at all. If a screenshot must be a JPEG, start at 90.

This is why automatic 'compress to target size' tools that apply one quality setting across a batch produce inconsistent results: the same number does very different things to a landscape and a screenshot.

The mistake that does the most damage

Recompression. Every time a lossy image is decoded, modified and re-encoded, it is quantised again — and the second pass is working on data that already has artefacts, which it then treats as real detail worth preserving while discarding something else.

The damage accumulates and is not recoverable. Saving a JPEG at quality 90 ten times in a row produces a visibly worse image than saving the original once at quality 60, despite the higher nominal setting each time.

The rule that follows: always edit from the highest-quality version you have, and export to lossy once, at the end. Never use a lossy file as your working master. If you need to send an image to someone who will edit it, send a lossless copy.

Hitting a target file size

Upload limits are the usual reason people compress at all — a form wants under 2 MB, or a forum caps attachments at 500 KB.

The order of operations matters and most people get it backwards. Reducing dimensions is far more powerful than reducing quality, because file size scales roughly with pixel count: halving both width and height cuts pixels to a quarter. Dropping a 4000-pixel-wide photo to 1600 pixels will usually get you under a limit on its own, at no perceptible cost, because nothing displaying it needed 4000 pixels.

So: resize first to the largest size the image will actually be displayed at, then compress, and only then start lowering quality below 80. A 1600-pixel image at quality 85 will look better and be smaller than a 4000-pixel image at quality 40.

Switching format is the other lever. The same image as WebP is typically 25–35% smaller than JPEG at matched quality, and AVIF smaller again — often enough on its own to clear a limit without touching quality.

Frequently asked questions

Does compressing an image twice make it worse?
Yes, and permanently. Each pass quantises data that already contains artefacts from the previous pass. Always work from the highest-quality original and export to a lossy format once.
What quality setting should I use for web images?
Between 75 and 85 for photographs — visually indistinguishable from the original at roughly half the file size. Start at 90 for screenshots, illustrations or anything with sharp edges and flat colour.
Why does my compressed sky look banded?
Smooth gradients have no texture to mask JPEG's 8×8 block boundaries, so adjacent blocks resolve to slightly different averages and the seams become visible. Raise the quality setting, or use WebP or AVIF, which handle gradients better.
Is it better to resize or compress to reduce file size?
Resize first, almost always. File size scales with pixel count, so halving the dimensions cuts the file to roughly a quarter with no visible loss if the image was larger than it needed to be. Then compress the resized version.

Tools mentioned in this guide

Keep reading