PNG vs JPG vs WebP: When to Use Each Image Format
Lossy vs lossless compression, when transparency matters, and why WebP is replacing both PNG and JPG on the web.
You drag a quality slider from 100 to 80 and your image shrinks by 75%. But what actually happens to the pixels? Understanding how compression works helps you make smarter decisions about file size vs. visual quality — and explains why a screenshot compresses completely differently from a photograph.
JPG compression happens in four stages, each one designed to exploit a different weakness in human vision:
What the quality slider actually does:
Quality 100 → Minimal quantization, near-lossless
Quality 80 → High frequencies reduced ~60%, barely visible
Quality 60 → Noticeable softness around sharp edges
Quality 30 → Obvious blocking artifacts (8×8 grid visible)
Quality 10 → Heavy distortion, abstract painting effectJPG is optimized for continuous-tone images — photographs where adjacent pixels have similar colors. Screenshots are the opposite: large flat color areas with razor-sharp text edges.
When the DCT encounters a sudden jump from white to black (like the edge of a letter), it needs high-frequency components to represent that transition accurately. Quantization crushes those high frequencies, creating visible “ringing” artifacts around the edge — a halo of ghostly color that wasn't in the original.
This is why a screenshot saved as JPG at quality 85 can look noticeably worse than the same screenshot as PNG, despite being a larger file. PNG's lossless DEFLATE algorithm handles flat colors and sharp transitions perfectly.
PNG uses a two-step lossless process:
200, 200, 200, 200, the filter stores 200, 0, 0, 0 (first value, then differences). Long runs of identical pixels produce long runs of zeros.This is why screenshots with large solid backgrounds compress amazingly well in PNG — the filter step produces massive runs of zeros that DEFLATE squashes to almost nothing. Photographs have almost no repeated patterns after filtering, so PNG files for photos are enormous.
WebP uses a more sophisticated version of block-based prediction. Instead of fixed 8×8 blocks like JPG, WebP uses variable-size blocks (4×4 up to 16×16) and can predict pixel values from neighboring blocks rather than encoding them directly. This produces 25–35% smaller files than JPG at equivalent visual quality.
AVIF takes this further by borrowing techniques from video compression (AV1), including larger block sizes, more prediction modes, and better entropy coding. The downside is encoding speed — creating an AVIF can be 10–20 times slower than creating a WebP.
Compression is about understanding what information matters and what can be safely discarded. The best compression strategy is the one that matches your content type — not the one with the smallest number on the quality slider.
Lossy vs lossless compression, when transparency matters, and why WebP is replacing both PNG and JPG on the web.
How QR encodes data in binary modules, why error correction lets you put logos in the center, and what those corner squares do.
Grid vs freeform composition, how canvas APIs stitch images together, and DPI considerations when combining images.