Technical GuideAugust 2026 • 8 min read

JPG Compression Explained: Quality, Size and Tradeoffs

An architectural exploration of JPEG encoding, discrete cosine transform, chroma subsampling (4:2:0 vs 4:4:4), and tuning MozJPEG for maximum efficiency.

The Engineering Behind JPEG Compression

The JPEG standard has endured for decades because its underlying mathematical architecture is brilliantly tuned to human perceptual biology. To understand how to achieve the best results with JPG compression, it helps to understand what happens inside the encoder during each stage of processing.

Phase 1: Color Space Conversion and Chroma Subsampling

Raw digital images start in the RGB color space. The JPEG encoder first converts RGB values into YCbCr:

• Y represents Luminance (grayscale brightness).

• Cb and Cr represent Blue-difference and Red-difference chrominance (color).

Because the human retina contains roughly 120 million rod photoreceptors (luminance) and only 6 million cone photoreceptors (color), the encoder can safely discard color resolution without human observers noticing.

In standard 4:2:0 chroma subsampling, color information is sampled at half the horizontal and vertical resolution of luminance, instantly eliminating 50% of the raw color data with virtually zero perceived degradation.

Phase 2: 8x8 Block Splitting and Discrete Cosine Transform (DCT)

The image is divided into small 8x8 pixel blocks. Each 8x8 block is processed using the Discrete Cosine Transform (DCT), converting spatial pixel intensity variations into a matrix of 64 frequency coefficients.

The top-left coefficient (DC component) represents average block brightness, while the remaining 63 coefficients (AC components) represent increasingly high-frequency, rapid visual changes.

Phase 3: Quantization and Huffman Entropy Coding

Quantization is where lossy compression actually occurs. Each frequency coefficient is divided by a corresponding value in a quantization matrix and rounded to the nearest integer.

High-frequency coefficients (fine noise and subtle textures) are rounded to zero. The resulting matrix of zeros is traversed in a zigzag pattern and packed tightly using Run-Length Encoding and Huffman entropy tables.

Why MozJPEG Produces Smaller Files than Standard JPEG

Mozilla developed MozJPEG to modernize JPEG encoding for web performance. MozJPEG introduces Trellis Quantization—an intelligent optimization algorithm that iteratively searches for the most mathematically efficient balance between visual distortion and byte length.

MozJPEG also enables progressive scan encoding by default, which renders a low-resolution preview instantly as image bytes stream in, while producing final files that are 5% to 15% smaller than baseline JPEG encoders.

ADVERTISEMENT

Frequently Asked Questions

What is the difference between baseline and progressive JPG?

Baseline JPG renders from top to bottom line-by-line. Progressive JPG renders a full-frame blurry preview immediately, sharpening as data downloads, and compresses 5%–10% smaller.

What does chroma subsampling 4:4:4 mean?

4:4:4 means zero color subsampling—full color resolution is preserved for every pixel. It is ideal for graphics with sharp red/blue text on dark backgrounds.

Why does MozJPEG compress better than standard Photoshop JPEG?

MozJPEG uses trellis quantization and optimized Huffman tables that calculate mathematically superior entropy packing.

What causes color banding in compressed JPGs?

Color banding occurs when subtle gradients are quantized into too few discrete color steps at low quality settings (below 60%).

Can JPG compression introduce security risks?

Standard JPG compression does not contain executable code, making it safe. However, unstripped EXIF metadata can leak private GPS coordinates.

Does Tocompress support MozJPEG?

Yes! Tocompress runs compiled MozJPEG WebAssembly directly in your web browser for state-of-the-art JPG compression.

Related Optimization Articles

Ready to Optimize Your Images?

Use our free, in-browser compression tools with 100% privacy guaranteed.

Try JPG Compressor