How JPEG compression works
The core insight of JPEG is that human vision is much better at seeing broad shapes and brightness than fine colour detail. So the encoder throws away the parts you are least likely to notice.
Concretely, it splits the image into 8×8 pixel blocks, converts each block into frequency components, and then discards the high-frequency ones according to a quality setting. Reconstruct the block from what remains and you get something very close to the original — close enough that at sensible settings the difference is invisible.
Two consequences follow, and they explain almost everything about JPG’s behaviour.
The loss is permanent. Once discarded, that detail is gone. Converting a JPG to a lossless format afterwards preserves what remains perfectly, but recovers nothing.
High-frequency detail suffers first. A hard edge — the boundary of a letter, a thin line in a diagram — is high-frequency detail. That is why JPG is superb for photographs and poor for screenshots and text.
Why it is still everywhere
JPEG is technically outclassed. On the fixed test image used across this site, the same source came out at 375 KB as JPG, 247 KB as WebP, and 109 KB as AVIF.
It survives on universality. Every operating system, every phone, every browser, every print shop, every photo frame, every upload form, every piece of software written since the mid-1990s can open a JPG. Nothing else on this list can claim that.
For anything you hand to another person, that is worth more than the bytes.
What JPG cannot do
- Transparency. No alpha channel, ever. Transparent areas become a solid colour.
- Lossless editing. Every save discards more. Edit in PNG and export to JPG at the end.
- Sharp text. See above; this is structural, not a quality-setting problem.
- More than 8 bits per channel. Fine for viewing, limiting for heavy editing.
Converting to and from JPG
Into JPG for compatibility: from HEIC, PNG, WebP or AVIF.
Out of JPG for size: to WebP or AVIF. Out of it for editing: to PNG, remembering that this preserves the damage rather than undoing it.
To make a JPG smaller without changing format, compress it and watch the measured trade-off.