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.
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.