Skip to main content
Utilavo

Image Compression: Lossy vs Lossless Explained

Updated 9 min read

By Utilavo Editorial · Reviewed

The decision behind image compression is which kind of error you can tolerate. Lossless compression preserves every pixel by exploiting redundancy in the bitstream; lossy compression throws away information the human visual system is least sensitive to. Picking the wrong axis ruins the result either way — running PNG-lossless on a 12 MP photo produces a 30 MB file that gains nothing, and running JPEG at quality 60 on a screenshot produces ringing artifacts around every line of text.

JPEG, defined in ITU-T T.81 and ISO/IEC 10918-1, achieves its compression through a discrete cosine transform on 8x8 blocks followed by quantization — the lossy step. PNG, specified by W3C / ISO 15948, uses the lossless DEFLATE algorithm (LZ77 + Huffman). WebP, documented at developers.google.com/speed/webp, supports both modes through entirely different codepaths. Knowing which transform applies to your image is the difference between a 90% size reduction and a corrupted result.

Lossy vs lossless: which transform applies

Lossless compression — PNG, WebP-lossless, lossless AVIF — reduces file size by encoding the bitstream more efficiently without altering pixel values. Decompressing returns the byte-exact original. The achievable ratio depends entirely on how predictable the image is; photographs full of fine detail compress poorly (1.5-3x), while screenshots with large flat areas compress excellently (5-10x). PNG specifically applies one of five row filters before DEFLATE to maximize predictability.

Lossy compression — JPEG, WebP-lossy, AVIF, HEIC — discards information that the human visual system is least sensitive to. JPEG's quantization step zeros out high-frequency DCT coefficients; the eye is far more sensitive to low-frequency luminance variation than to high-frequency chrominance, which is why JPEG can drop most of the chroma channel detail without visible damage. At quality 80-85, typical photographs compress to 5-10% of an uncompressed bitmap with no perceptible artifacts.

Why quality 85 is the magic number

JPEG's quality slider does not map linearly to perceived quality. Above quality 90, you are mostly preserving high-frequency noise that the eye cannot resolve at typical viewing distances; below quality 70, the quantization tables zero out enough coefficients to produce visible blocking and ringing. Quality 80-85 sits at the knee of the rate-distortion curve where additional quality buys very little perceived improvement and additional compression starts to cost visible quality. This is why sites like Google's PageSpeed Insights and Squoosh default to roughly that range.

WebP's quality scale is roughly equivalent to JPEG's at the same number, but the underlying VP8 codec produces sharper edges at low quality. WebP at 75 typically looks better than JPEG at 75. AVIF's scale is different again — AVIF quality 50 is roughly comparable to JPEG quality 80, and AVIF quality 30 is still acceptable for most photographs.

Format-specific quirks that catch people out

PNG-24 is rarely the right choice. If the image needs transparency, use PNG-32 (8-bit alpha). If it does not need transparency and is photographic, use JPEG or WebP. PNG-24 produces the largest file with no compensating benefit. PNG-8 (indexed-color, up to 256 colors) is dramatically smaller for simple graphics and is what most icon sprites should use.

WebP has two encoder paths — one based on VP8 for lossy and one based on prediction for lossless — and they produce different outputs even at the same nominal quality. The lossless path is documented in the libwebp encoder reference and uses a chained predictor, color transform, and entropy coder. For images with both photographic regions and crisp graphics (e.g., a screenshot with embedded photos), neither WebP path is ideal — consider splitting the regions.

JPEG's chroma subsampling default is 4:2:0, which halves the chrominance resolution in both axes. This is invisible on photographs but produces visible color smearing on saturated red text against a contrasting background — the classic 'red text on blue' artifact. If you must JPEG-encode an image with sharp colored text, force 4:4:4 chroma (no subsampling) at the cost of larger files.

The resize-then-compress rule

Always resize to the actual display dimensions before compressing. The leverage is enormous: a 4000-pixel-wide photo resized to 1200 pixels for web use is already 89% smaller before any compression runs (1200² / 4000² ≈ 0.09). Compressing the resized image then targets the final byte budget. The reverse — compressing first, then resizing — wastes compute and loses quality, because you are throwing away detail that the resize would have removed anyway, and the resize-after step has less signal to work with.

Use Compress Image after resizing for the final size step. The tool preserves EXIF orientation tags so portrait photos display correctly. For format conversion as part of the pipeline, Image Converter handles JPEG/PNG/WebP/AVIF/HEIC interconversion.

Key takeaways

  • Lossy compression (JPEG, WebP, AVIF) is for photographs; lossless (PNG, WebP-lossless) is for screenshots, diagrams, and graphics with text.
  • Quality 80-85 is the rate-distortion knee for JPEG and WebP — additional quality above that is wasted, additional compression below it is visible.
  • Always resize before compressing — the dimensional reduction has more leverage than any quality setting.
  • JPEG 4:2:0 chroma subsampling smears saturated colored text; force 4:4:4 if your image has red or magenta text on contrasting backgrounds.
  • PNG-24 is almost never the right choice — use PNG-32 (transparency) or JPEG/WebP (no transparency).

Frequently asked questions

Why does my JPEG of a screenshot look blurry around the text?

JPEG's discrete cosine transform handles smooth gradients well but produces ringing artifacts around sharp edges — exactly what text consists of. Screenshots and diagrams should use PNG or WebP-lossless, not JPEG. If the file must be JPEG, set quality to 95+ and disable chroma subsampling, but even then the result will be larger and lower quality than a PNG.

Why does compressing the same JPEG twice make it noticeably worse?

Each JPEG encode quantizes DCT coefficients, and the quantization grid does not align between successive encodes. Re-encoding shifts the grid, causing previously-quantized values to be re-quantized in slightly different bins — this is generation loss. Always re-encode from the original lossless source, never from a previously compressed JPEG. Lossless formats (PNG, WebP-lossless) do not suffer from this.

Why is my WebP file larger than the PNG for a simple icon?

Lossless WebP outperforms PNG on most images, but PNG-8 (indexed color, up to 256 colors) is extremely efficient on simple graphics and can beat lossless WebP. If the icon has 16 colors, PNG-8 may be 30% smaller than lossless WebP. The break-even depends on color count and entropy.

Why are my AVIF files taking minutes to encode?

AVIF uses the AV1 video codec, designed for compression efficiency over encoder speed. Default encoder settings prioritize quality, and a single high-resolution image can take 30-90 seconds. Lower the encoder speed setting (libavif's `--speed 6` or higher) to trade compression efficiency for time, or use WebP if encoding speed matters more than file size.

Should I strip EXIF metadata when compressing?

For web delivery, yes — EXIF can add 5-50 KB per image and may leak GPS coordinates from phone cameras. The Compress Image tool preserves the EXIF orientation tag (which it must, to render rotated photos correctly) and can strip everything else. For archival, keep the EXIF; for public web use, drop it.

How does Utilavo handle uploaded images?

See the processing model for transport and retention details on server-side image processing.