pythonware.com

Home / Guides / JPEG quality

Guide

How JPEG quality maps to file size

The quality slider is the most misread control in image work. It is not a percentage of anything, and moving it from 100 to 50 does not halve the file.

What the number does

JPEG divides an image into blocks, converts each block into a set of frequency coefficients, and then throws some of them away. The quality number selects a table of divisors that decides how aggressively that discarding happens. Low frequencies, which carry broad shapes and tones, are preserved. High frequencies, which carry fine detail and sharp edges, are the first to go.

So quality does not scale the file. It scales how much detail survives, and the file size follows from how much detail your particular image happened to have.

The shape of the curve

The relationship is steeply non-linear, and the useful consequence is that the top of the range is nearly free to give up.

100Enormous, and visually identical to 95. Almost never worth it.
90 to 95Archival. Roughly half the size of 100 with no visible difference.
75 to 85The working range. Most photographs are indistinguishable from the original at normal viewing size, at perhaps a fifth of the bytes.
60 to 75Artefacts start appearing in flat areas such as skies, and around hard edges. Fine for a thumbnail.
Below 50Visible block structure. Only for hitting a hard byte limit when nothing else will do.

Dropping from 100 to 90 might remove half the file. Dropping from 60 to 50 might remove a tenth of what is left, while doing far more visible damage. If you are trying to reach a target, the first thing to reduce is almost always the dimensions rather than the quality.

Dimensions beat quality

File size scales roughly with pixel count, which scales with the square of the dimensions. Halving the width and height quarters the number of pixels, and typically cuts the file by about three quarters, with no artefacts at all: a smaller picture is still a clean picture. A 4000 pixel wide photograph displayed in a 800 pixel column is carrying twenty-five times the data it needs.

This is why the compressors on this site reduce dimensions before pushing the quality into the ugly range, and why they show you both numbers when they are done.

When JPEG is the wrong format entirely

JPEG was designed for photographs, which are full of gradual tonal change. It handles that beautifully and handles the opposite case badly. Screenshots, diagrams, logos, and anything with large flat areas and hard black-on-white edges come out with a visible mottled halo around every line, and often end up larger than a PNG of the same image would be. For those, use PNG. For photographs on the web, WebP typically beats JPEG by a comfortable margin at matching quality.

Every save costs something

JPEG is lossy every single time, not just the first. Opening a JPEG, changing nothing and saving it again still degrades it, because the image has to be decoded and re-encoded and the encoder makes its decisions afresh. Editing the same file repeatedly compounds this until it looks visibly soft and blotchy. Keep an original in a lossless format if the image matters, and always process from that.