WEBPery

How WebP compresses images: VP8 lossy macroblock prediction and VP8L lossless transforms behind 25–34% smaller files.

How VP8 and VP8L Encoding Works

WebP uses two separate compression engines. VP8 handles lossy data using predictive coding borrowed from video. VP8L handles lossless data using reversible pixel transforms and entropy coding. Understanding both explains why WebP beats JPEG on photographs and PNG on graphics. This guide covers the mechanics of each engine.

For the practical choice between modes, see Lossy vs Lossless Compression: When to Use Each for WebP. For the broader format definition, see What is WebP?.

Which compression engines does WebP use?

WebP uses two engines: VP8 for lossy compression and VP8L for lossless compression. VP8 derives from the VP8 video codec and applies its intra-frame coding to single still images. VP8L is a dedicated lossless engine designed specifically for WebP.

A WebP file stores its data in one of these forms — never both. The RIFF container marks which engine produced the data using a VP8 or VP8L chunk identifier.

How does VP8 lossy compression work?

VP8 lossy compression predicts each region of an image from its surroundings, then stores only the prediction error. The encoder splits the image into 16×16-pixel macroblocks, predicts each block, transforms the residual error, and quantises it according to a quality factor.

The pipeline runs in four stages:

  1. Macroblock division — the image is divided into 16×16-pixel blocks, subdivided into 4×4 sub-blocks for prediction.
  2. Intra-prediction — each block is predicted from already-decoded neighbouring pixels above and to the left.
  3. Transform and quantisation — the difference between prediction and actual content is transformed with a discrete cosine transform, then quantised. Quantisation is where data is discarded.
  4. Entropy coding — the quantised coefficients are compressed with a boolean arithmetic coder.

The quality factor (-q, 0–100) controls quantisation aggressiveness. Lower values discard more data, producing smaller files with more artefacts.

What does the quality factor change?

The quality factor sets how coarsely VP8 quantises prediction error. Higher quality keeps finer error detail and produces larger files. Lower quality rounds error more coarsely, shrinking files and introducing blocking, ringing, and banding artefacts.

Quality does not scale linearly. The range q=90–100 loses almost nothing; q=80–90 loses a little; below q=60 artefacts become visible during normal viewing. Encoder parameters are detailed in WebP Compression Settings.

How does VP8L lossless compression work?

VP8L lossless compression rewrites pixel data using four reversible transforms, then compresses the result with entropy coding. No data is discarded — the decoded image is bit-identical to the source. The transforms expose redundancy that the entropy coder then removes.

VP8L applies these transforms:

  • Predictor transform — describes each pixel as the difference from a prediction based on neighbouring pixels, using 14 prediction modes.
  • Colour transform — decorrelates the red, green, and blue channels by predicting red and blue from green.
  • Subtract-green transform — subtracts the green value from red and blue, since photographic luminance is green-dominant.
  • Colour indexing transform — replaces full RGB values with a palette index for images with 256 or fewer colours.

After transforms, VP8L uses LZ77 backward references, Huffman coding, and a colour cache to compress repeated pixel sequences. The result is roughly 26% smaller than PNG.

Why is WebP smaller than JPEG and PNG?

WebP is smaller because its engines are more efficient than the older formats. VP8 uses block prediction that JPEG's purely transform-based encoding lacks. VP8L combines four transforms with LZ77 references, whereas PNG uses only a single filter step plus DEFLATE.

Concrete reductions: WebP lossy is 25–34% smaller than JPEG at matched quality, and WebP lossless is ~26% smaller than PNG. See WebP vs JPEG and WebP vs PNG for side-by-side data.

What is near-lossless mode?

Near-lossless mode applies lossless encoding after lightly pre-processing pixels to improve compressibility. It reduces file size 25–40% below full lossless while remaining visually indistinguishable from the source. It suits screenshots, charts, and document scans that mix photographic and graphic content.

Near-lossless is controlled by the -near_lossless parameter (0–100). Details are in WebP Compression Settings.

How does WebP compression affect transparency and animation?

Both engines support an alpha channel, but they store it differently. VP8L encodes alpha inline with colour data. VP8 stores alpha in a separate, losslessly compressed chunk, so transparency stays exact even when colour is lossy. Animation applies either engine per frame.

These behaviours are covered in WebP Transparency and WebP Animation.

Where to go from here

VP8 and VP8L are why one format covers both photographs and graphics. Lossy prediction shrinks continuous-tone images; lossless transforms shrink flat-colour graphics — each beating the format it replaces.

What is WebP? A Complete Guide to the WebP Image Format

WebP is Google's image format with lossy and lossless compression. Learn how it works, browser support, file sizes, transparency, and animation.

WebP Transparency: Alpha Channel Support

WebP supports an 8-bit alpha channel in lossy and lossless modes. How transparency is stored, the ALPH chunk, file-size cost, and PNG comparison.

srcset and WebP: Responsive Images with Format Fallback

Use srcset and sizes to serve responsive WebP at the right resolution per device, with a JPEG fallback. Width and density descriptors explained.

WebP File Structure: RIFF Container and Chunk Format

How a WebP file is structured: the RIFF container, the WEBP FourCC, and VP8, VP8L, VP8X, ALPH, ANIM and ANMF chunks. The byte layout explained clearly.