Rasp

Explainer

Lossy vs lossless compression

One throws detail away to save space. The other never does. Almost every confusing thing about file conversion comes from mixing them up.

What is the difference between lossy and lossless compression?

Lossy compression permanently discards detail to make a file smaller, and the discarded detail can never be recovered. Lossless compression stores everything exactly, describing it more compactly, so the original is perfectly reconstructable. JPG, WebP and AVIF are lossy; PNG is lossless.

The distinction in one line

Lossless compression describes the same data more compactly. Nothing is lost; the original is perfectly reconstructable.

Lossy compression throws data away and keeps a good approximation. The thrown-away part is gone permanently.

That is the whole idea. Everything below is consequences.

How lossy compression gets away with it

It sounds reckless to discard parts of a picture. It works because human vision is uneven.

We are very good at seeing brightness and broad shapes, and comparatively poor at seeing fine colour variation and high-frequency detail. JPEG exploits exactly that: it converts blocks of the image into frequency components and discards the ones the eye is worst at noticing.

At sensible settings the result is genuinely indistinguishable from the original at normal viewing sizes — while being roughly a tenth of the size. On our fixed test image, 3.97 MB losslessly against 375 KB lossily.

That is a remarkable trade, and it is why nearly every photograph you have ever seen on a screen was lossily compressed.

Where lossy compression fails

The same mechanism that makes JPG excellent for photographs makes it terrible for text.

A hard black letter against white paper is high-frequency detail. Discarding high-frequency detail is what the codec does. So you get grey haloing around every character — obvious at a glance, and permanent.

This is why screenshots belong in PNG and photographs do not. It is not a quality-setting problem; it is structural.

Generation loss

Here is the consequence people meet without understanding it.

Open a JPG, edit it, save it. Open it again, edit, save. Repeat. The image degrades each time, because each save discards detail from an image that had already lost some.

Lossless formats have no such behaviour. A PNG saved a thousand times is bit-for-bit what it started as.

The practical rule: edit in a lossless format, export to a lossy one at the end. Not the other way round, and never repeatedly.

The misconception worth correcting

“I’ll convert my JPG to PNG to stop losing quality.”

Half right, and the half that is wrong causes real disappointment.

PNG will faithfully preserve whatever it is given — but what it is given is the output of JPG compression, detail already discarded. You get a perfect copy of a damaged picture, at roughly six times the size.

Converting JPG to PNG is a way to stop losing quality from this point forward. It is not restoration. Nothing is.

Lossless compression is not magic either

It is easy to assume lossless means “no compression”. It does not — it means no loss.

A PNG finds genuine patterns: runs of identical pixels, rows that resemble the one above, and encodes them compactly. On a screenshot with large flat areas, that works superbly. On a photograph, where every pixel differs slightly from its neighbour, there is very little exact repetition to find, so the file stays large.

You can also optimise a lossless file losslessly — searching for a more efficient encoding of exactly the same data. That is what oxipng does, and on our photographic test image it recovered 15% without altering a single pixel.

Which formats are which

Format Compression
PNG Lossless
JPG Lossy
WebP Both — lossy in normal use
AVIF Both — lossy in normal use
HEIC Lossy in normal use

Choosing, in practice

Use lossy for photographs going anywhere — email, a website, a print service. The saving is enormous and the loss is invisible.

Use lossless for screenshots and diagrams, for any working copy you will edit again, and for anything where a pixel being exactly right matters.

Never convert repeatedly between lossy formats. Each hop discards more, and spends bits faithfully reproducing the previous format’s artefacts. Go from your best available source, once.

Questions

Is JPG lossy or lossless?
Lossy. Every save discards image data permanently. PNG is lossless. WebP and AVIF can do both, but are used lossily in almost all cases, including on this site.
Does converting a JPG to PNG restore quality?
No — this is the most common misconception in the whole subject. PNG faithfully preserves whatever it is given, and what it is given is an image that has already lost detail. You get a perfect copy of a damaged picture.
Why does my image get worse every time I save it?
Because each lossy save discards detail from the already-degraded previous version. This is generation loss. Editing in a lossless format and exporting to a lossy one only at the end avoids it entirely.
Which is better?
Neither, in general. Lossy is right for photographs, where the discarded detail is genuinely imperceptible and the size saving is enormous. Lossless is right for text, diagrams and working copies, where exactness matters more than size.
How much smaller is lossy compression?
On our fixed test image, the same photograph was 3.97 MB losslessly as PNG and 375 KB lossily as JPG — around 91% smaller. For photographic content the gap is always large.
Can lossless compression make a file smaller at all?
Yes, by describing the same data more compactly — finding runs of identical pixels, rows resembling the row above. It works very well on flat graphics and poorly on photographs. Lossless optimisation of our photographic test PNG saved 15%.
Is lossy compression bad for archiving?
For a master copy, yes — archive whatever the highest-quality original is, which for a camera is usually a raw file or the original JPG from the sensor. Re-encoding an archive into another lossy format is the thing to avoid.

Sources