How JPEG Compression Works (And Why It's Still Everywhere)

JPEG is one of the oldest image formats (1992) yet still the most efficient for photographs. Understanding how it works explains why it is hard to beat for certain images.

DCT: Discrete Cosine Transform

JPEG splits images into 8×8 pixel blocks. Each block undergoes DCT math, converting pixels to frequency domain (high-frequency vs. low-frequency components).

Quantization: The Lossy Step

High-frequency components (fine details) are quantized (rounded) heavily. Low-frequency components (broad colors) are preserved. Human vision is more sensitive to color than detail, hence lossy compression works.

Huffman Coding: The Final Compression

Quantized values are Huffman-coded (run-length encoding). Repeated values compress well. Final JPEG file is 20–50KB vs 5MB original.

Why It Works

JPEG exploits two facts: (1) Human eyes are more sensitive to luminance (brightness) than chrominance (color). (2) Human eyes are less sensitive to high-frequency detail. JPEG preserves what matters and discards what we cannot see.

Quality Setting Explained

Quality 100: minimal quantization, larger file. Quality 50: moderate quantization, artifacts visible but minor. Quality 10: extreme quantization, visible compression. Quality 85 is usually the sweet spot.

Progressive JPEG

Standard JPEG decodes top-to-bottom. Progressive JPEG decodes multiple passes, showing blurry then sharp image. Same file size, better perceived performance.

Why JPEG Persists

35 years of optimization, universal support, and good compression for photographs make JPEG still competitive with newer formats. WebP and AVIF are better, but JPEG is "good enough" and ubiquitous.

When JPEG Fails

Text, UI, flat colors: JPEG creates visible artifacts. PNG or WebP excels here. Photographs: JPEG is still excellent and widely supported.