I spent a weekend in 2025 trying to understand why WebP files were so much smaller than JPEGs. I ended up reading the WebP spec, the JPEG whitepaper from 1992, and half a dozen signal processing articles. Here's what I learned, in terms that don't require an EE degree.
| Lossless | Lossy | |
|---|---|---|
| How it works | Finds exact patterns, encodes them more efficiently | Discards data human eyes can't easily see |
| Quality | 100% identical to original | Visually near-identical, not pixel-perfect |
| File size | Moderate reduction (20-50%) | Dramatic reduction (70-95%) |
| Formats | PNG, GIF, WebP (lossless mode) | JPEG, WebP (lossy mode), AVIF |
| Best for | Logos, text, icons, screenshots | Photos, gradients, complex images |
Think of lossless compression like shorthand. Instead of writing "blue pixel, blue pixel, blue pixel, blue pixel" (4 data points), you write "4× blue pixel" (2 data points). This is called run-length encoding, and it's the simplest form of lossless compression.
PNG uses a more sophisticated algorithm called DEFLATE, which combines two techniques:
The result: PNG files are typically 20-40% smaller than uncompressed, and every single pixel is mathematically identical to the original.
Lossy compression goes further by exploiting human visual perception. Your eyes are more sensitive to brightness changes than color changes, and more sensitive to large-scale patterns than fine texture. JPEG exploits this brilliantly:
JPEG converts RGB to YCbCr (luminance + two color channels), then typically downsamples the color channels by 2x or 4x. Your eye barely notices because brightness carries most of the detail perception.
The image is divided into 8×8 pixel blocks. Each block is transformed from the spatial domain (pixel positions) to the frequency domain using DCT — the same math behind MP3 audio compression. The result is a matrix where the top-left values represent broad color changes and the bottom-right represents fine texture.
The frequency values are divided by a quantization table and rounded to integers. High-frequency (fine detail) values often round to zero. This is the only lossy step — and the quality slider in every JPEG compressor controls exactly how aggressively this division happens.
The resulting sparse matrix (lots of zeros) is then compressed losslessly using Huffman coding, similar to PNG's final step.
JPEG's DCT-based approach was invented in 1992. Modern formats use techniques from video codecs:
The result: WebP images are 25-35% smaller than equivalent-quality JPEGs. AVIF images are 50% smaller. The tradeoff is encoding speed — WebP takes 2-3x longer to encode than JPEG, and AVIF takes 5-10x longer.
For the WebP2PNG converter itself, I use WebP at quality 80 for everything. It's the sweet spot I found after compressing the same 50 test images at every quality level from 10 to 100 — files are 70-85% smaller than the original JPEG, and I can't tell the difference in a blind comparison. For the blog screenshots, I use PNG because text compression artifacts are genuinely distracting. For anything I'm archiving long-term, I keep the original format — compression is lossy by definition, and disk space is cheaper than re-shooting a photo.