Learn / Compression

Lossy vs. lossless compression, explained

Two completely different bets on what you're willing to give up for a smaller file — and which bet each format actually makes.

Every general-purpose image format makes one of two fundamentally different bets about what happens to your data when you compress it. Understanding which bet a format is making — not just how each performs, but why — is what actually predicts whether it's the right choice for what you're doing.

Lossless: perfect reconstruction, worse ratios

Lossless compression guarantees you get back exactly the data you started with, bit for bit, no exceptions. PNG and lossless WebP both work this way — they find genuinely redundant patterns in the data (repeated pixel runs, predictable structure) and encode those more efficiently, without ever throwing away information a decoder can't perfectly recover. This is why PNG is the right default for screenshots, UI graphics, and anything with flat color fields or sharp edges — that kind of content has a lot of genuine redundancy to exploit, and there's zero tolerance for the softening lossy compression would introduce around sharp edges and text.

Lossy: deliberate, informed loss

Lossy compression takes a different bet entirely: it deliberately discards information, specifically choosing what to discard based on what human vision is least likely to notice. JPEG, lossy WebP, and AVIF all work this way — most of their real compression gain comes from techniques like chroma subsampling and quantizing high-frequency detail more aggressively than low-frequency detail, not from finding literal redundancy. For photographic content, this trades a small, usually-invisible quality cost for a dramatically smaller file — often 5-10x smaller than a lossless equivalent at comparable perceived quality.

The quality knob is really a loss knob

A lossy format's "quality" setting isn't really controlling quality directly — it's controlling how much gets discarded before encoding. Lower quality settings quantize more aggressively (rounding more values to the same output, discarding finer distinctions), which is why quality sliders and file size move in opposite directions: less real information kept means less data needed to store it.

Lossy compression is not idempotent — re-saving an already-lossy file through another lossy pass doesn't just fail to improve it, it actively compounds the loss, because the second pass is quantizing an image that's already missing information the first pass discarded. A gain-map HDR JPEG makes this doubly relevant: it bundles two separate lossy JPEGs (the primary and the gain map), so re-optimizing the whole file degrades both.

Applying this practically

Use lossless (PNG, or lossless WebP) for anything with sharp edges, flat color, or text — screenshots, logos, diagrams — where fidelity matters more than file size and the redundancy-based compression actually has something real to exploit. Use lossy (JPEG, AVIF, lossy WebP) for photographs, where the visual cost of discarding imperceptible detail is genuinely worth the size savings. Optimize supports both directions — a real quality-controlled lossy encode when you choose JPEG or lossy WebP output, and true lossless compression when you choose PNG.

Questions people actually ask

Which does Optimize use?
For JPEG and lossy WebP output, a genuine quality-controlled lossy encode — the quality slider directly controls how much detail gets discarded. For PNG output, compression is lossless; there's no quality slider because there's nothing to trade off.
Does re-optimizing an already-compressed HDR JPEG lose more quality?
Yes, and it compounds in both places. A gain-map HDR JPEG bundles two separate lossy JPEGs — the primary image and the gain map — so re-encoding the whole file applies generational loss to both, not just the visible photo.
If lossless never loses quality, why doesn't everyone just use it?
Because the compression ratio is much worse for photographic content. Lossless formats can't discard anything a human wouldn't notice — they have to preserve every pixel exactly — so a photo that would compress to a few hundred KB as JPEG might be several MB as a lossless equivalent.