Why Is WebP Smaller Than JPEG?
WebP achieves substantially smaller file sizes than JPEG by employing modern predictive coding techniques originally designed for video compression, utilizing flexible block partitioning, and applying superior entropy encoding. While JPEG treats images as isolated 8x8 pixel blocks converted via the Discrete Cosine Transform, WebP analyzes spatial patterns across surrounding pixels to predict content before compressing only the residual error. This architectural shift enables WebP to deliver equivalent visual fidelity at 25% to 34% smaller file sizes on average.
Predictive Intra-Frame Coding
The primary architectural advantage of WebP stems from its derivation from the VP8 video codec. WebP uses intra-frame predictive coding, which treats an image like a single keyframe in a video stream.
Instead of encoding every pixel from scratch, the encoder divides the image into macroblocks and predicts the pixel values of the current block based on neighboring, previously decoded blocks directly above and to the left. The encoder supports several prediction modes:
- Horizontal Prediction: Extrapolates columns across the block using the pixel values immediately to the left.
- Vertical Prediction: Extrapolates rows downward using the pixel values directly above the block.
- DC (Average) Prediction: Fills the block with the mean value of the neighboring top and left pixels.
- TrueMotion Prediction: Uses both the neighboring pixels and the corner pixel to model subtle directional gradients across the block.
Once a prediction is calculated, WebP subtracts it from the actual pixel data. The encoder only needs to compress the difference—termed the residual error. Because well-predicted blocks leave minimal residual data, the amount of information requiring compression is drastically reduced compared to JPEG's approach of encoding raw pixel values.
Variable Block Partitioning
JPEG divides images into a rigid, fixed grid of 8x8 pixel blocks across the entire frame. This rigid structure forces uniform processing regardless of whether a region contains high-frequency detail or a flat, uniform background.
WebP utilizes 16x16 pixel macroblocks that can be adaptively divided into smaller sub-blocks down to 4x4 pixels:
- Smooth Regions: In flat areas like skies or blurred backgrounds, WebP uses large 16x16 macroblocks with a single prediction mode, saving significant header and transform overhead.
- Detailed Regions: In high-contrast areas with sharp edges or intricate textures, WebP subdivides macroblocks into sixteen 4x4 sub-blocks, applying distinct prediction modes to each to capture detail accurately.
This spatial adaptability prevents the format from wasting data bits on low-complexity image regions while preserving clarity where it matters most.
Advanced Transform and Quantization
After prediction produces the residual error, WebP transforms the spatial data into frequency components to discard information imperceptible to the human eye.
While JPEG relies on the classical Discrete Cosine Transform (DCT), lossy WebP implements an integer-based approximation of the discrete cosine transform (specifically an 8-bit, 4x4 transform known as the Walsh-Hadamard Transform for certain luminance components alongside standard 4x4 DCT approximations).
Integer transforms avoid the floating-point rounding errors common in legacy JPEG encoders, preventing drift and rounding artifacts between different operating systems and decoders. Furthermore, WebP segments the image into up to four distinct complexity segments, assigning independent quantization parameters to each segment to tailor compression intensity precisely across varied image textures.
Modern Entropy Encoding: Arithmetic vs. Huffman
The final step in both codecs is entropy encoding, which translates processed symbols into bits.
JPEG historically relies on Huffman coding, a technique that maps symbols to integer bit lengths (e.g., 1 bit, 2 bits, 3 bits). Because an individual symbol cannot be represented by a fractional number of bits, Huffman coding regularly rounds up bit lengths, resulting in mathematical inefficiency.
WebP replaces Huffman coding with a boolean arithmetic encoder (an implementation of arithmetic coding). Arithmetic coding maps an entire sequence of symbols to a single arbitrary-precision fractional value between 0 and 1. This permits the storage of high-probability symbols at fractional-bit costs (such as 0.3 bits per symbol), allowing WebP to reach compression ratios much closer to the theoretical Shannon entropy limit.
Artifact Mitigation and Edge Retention
When JPEG files are compressed aggressively, the rigid 8x8 grid manifests as visible block boundaries—commonly known as "blocking artifacts"—alongside high-frequency "ringing" around hard edges.
WebP mitigates these compression flaws through an integrated, in-loop deblocking filter. Because the filter operates within the decoding loop, subsequent block predictions leverage the filtered pixels, preventing boundary discrepancies from compounding across the image. The result is a smoother degradation curve at low bitrates, retaining structural cohesion and edge clarity where standard JPEG degrades into fragmented blocks.