Lossy vs Lossless: How Image Compression Actually Works
Save a photograph as a JPEG and it shrinks to a fraction of its size while looking essentially identical. Save a crisp logo or a screenshot of text the same way and the edges turn fuzzy and speckled. The reason comes down to a single decision every image format makes: whether to compress lossily or losslessly. Understand that choice and you will stop guessing about formats and quality sliders forever.
Key Takeaways
- Lossless compression shrinks a file while preserving every original pixel exactly.
- Lossy compression achieves far smaller files by permanently discarding detail the eye barely notices.
- Use lossy for photographs; use lossless (or near-lossless) for logos, line art, and text-heavy graphics.
- Re-saving a lossy file repeatedly causes cumulative "generation loss" — always compress from the original.
What Compression Is Really Doing
An uncompressed image is just a grid of pixels, each storing a colour value. A modest 1200×800 photo contains nearly a million pixels — several megabytes of raw data. Compression is the art of representing that same picture with far fewer bytes. There are two fundamentally different philosophies for doing it.
Lossless Compression: Nothing Is Thrown Away
Lossless compression finds and removes redundancy without discarding any actual information. If a banner has 500 identical blue pixels in a row, instead of storing the colour 500 times, the encoder records "blue × 500." Decompress the file and you get back a pixel-perfect, bit-for-bit copy of the original. Techniques like run-length encoding and the DEFLATE algorithm power this approach.
The trade-off is modest savings. Because nothing is sacrificed, lossless files stay relatively large — especially for photographs, which have few exactly-repeating regions. PNG, GIF, and the lossless mode of WebP are the common lossless web formats. They shine for graphics with large flat areas of solid colour and sharp edges: logos, icons, diagrams, and screenshots.
Lossy Compression: Discarding What You Won't Miss
Lossy compression makes a bolder bet: that the human eye is imperfect, and that some detail can be permanently deleted without anyone noticing. Formats like JPEG, and the lossy modes of WebP and AVIF, exploit the quirks of human vision — for instance, we are far more sensitive to changes in brightness than to subtle shifts in colour.
Under the hood, the encoder breaks the image into small blocks, transforms each into frequency components, and then aggressively rounds off the high-frequency detail we are least likely to perceive. The discarded information is gone for good — but in exchange, lossy files can be five or ten times smaller than lossless equivalents. For photographs, with their smooth gradients and rich texture, the visual cost is usually invisible and the size win is enormous.
Why logos turn to mush
Lossy compression hates sharp, high-contrast edges — exactly what text and line art are made of. Those crisp boundaries are "high-frequency" detail, the very thing the encoder discards first. The result is the tell-tale haze and coloured speckles ("artifacts") around letters. That is why a logo belongs in a lossless PNG or WebP, not a JPEG.
The Quality Slider, Demystified
When you export a JPEG or WebP at "80% quality," you are setting how aggressively the encoder rounds off detail. Lower numbers discard more and produce smaller files; higher numbers preserve more and produce larger ones. The relationship is not linear — there is a sweet spot, typically around 75–85 for web photography, where files are dramatically smaller yet remain visually indistinguishable from the original. Push much below that and artifacts become obvious; push much above it and you pay a large size penalty for quality no one can see.
Choosing the Right Approach
- Photographs and complex images — lossy (WebP or AVIF). The size savings are huge and quality loss is imperceptible at sensible settings.
- Logos, icons, line art, diagrams — lossless (PNG or lossless WebP) to keep edges razor-sharp.
- Screenshots — lossless if they contain text; lossy is acceptable for screenshots of photos.
- Images needing transparency — PNG or WebP, both of which support an alpha channel (and WebP supports lossy transparency, which JPEG cannot).
Beware Generation Loss
Because lossy compression discards data every time it runs, repeatedly opening and re-saving a JPEG degrades it a little more each round — like photocopying a photocopy. The artifacts accumulate and become permanent. The defence is simple: keep a pristine master in a lossless format (or the camera original), and always generate your compressed web versions from that master, never from a previously compressed copy.
Find your quality sweet spot
Experiment with the quality slider and watch the file size respond in real time. Our free browser tool converts to WebP locally — tune lossy compression without ever uploading your originals.
Optimize Images NowAbout WebPMagic
WebPMagic is an independent project focused on image optimization and web performance. These guides are researched and edited to give developers clear, practical, and accurate information for building faster websites, with tips drawn from hands-on use of our own WebP conversion tool. Found an error or have a suggestion? Let us know via our contact page.