← Back to Home

How WebP Compression Works

What happens inside a WebP file: lossy, lossless, alpha and animation.

By the CompressItAll team. Published 2025-11-22. Updated 2026-10-24.

Compress WebP images with our free tool

Quick Summary

  • WebP is one container with two different codecs: a lossy one derived from the VP8 video codec and a separate lossless one often called VP8L.
  • Both modes can carry transparency, and the format can store animation.
  • Lossy WebP predicts each block from its neighbours, transforms the leftover difference and quantises it.
  • Lossless WebP uses prediction, colour decorrelation and a palette of recent pixels before entropy coding.

This page covers what is inside the format. For converting and serving files, go to the WebP Optimization Guide. For choosing between WebP, PNG and JPEG, see WebP vs PNG vs JPEG.

WebP lossy compression: original file size compared to compressed output at quality 85. Placeholder for real measurement.
Placeholder — replace with real measurement from compressitall.com/compress-webp/ (lossy mode, quality 85)

WebP Format Overview

Google released WebP to give web pages an image format that handles photographs, graphics and transparency in a single family. A WebP file is a RIFF container. Inside it, a chunk tells the decoder whether the picture data is lossy or lossless, and extra chunks can hold an alpha channel, animation frames, a colour profile and metadata. One extension, .webp, therefore covers quite different encodings, which is worth remembering when you compare file sizes. See the WebP RIFF container specification (Google Developers).

Lossy WebP: The VP8 Approach

Lossy WebP uses the intra-frame coding tools of VP8, a video codec, as documented in the WebP compression documentation (Google Developers). Video codecs treat a still frame as a keyframe, so a lossy WebP image behaves like a single compressed video frame. The stages look like this:

  1. Colour conversion and subsampling. The image is converted to a YUV representation, and the colour channels are stored at half resolution in each direction, as in 4:2:0 JPEG.
  2. Macroblocks. The picture is split into 16x16 macroblocks, which are divided into smaller blocks for transformation.
  3. Prediction. Each block is predicted from pixels already decoded above and to the left. Several prediction directions are available, and the encoder picks the one that leaves the smallest remainder.
  4. Transform. Only the difference between the prediction and the real pixels, called the residual, is transformed, using a DCT-style transform on small blocks.
  5. Quantisation. The transform coefficients are rounded using a quantiser. This is the main lossy step, and the quality setting mostly controls it. The encoder can vary the quantiser between regions of the image using segments.
  6. Entropy coding. The result is packed with an arithmetic coder, which adapts to statistics of the data.
  7. Loop filtering. The decoder applies a filter to soften the seams between blocks, which reduces visible blocking.

Compared with the process described in How JPEG Compression Works, the main differences are prediction from neighbouring blocks, the in-loop deblocking filter and arithmetic rather than Huffman coding. These tools let the encoder spend bits where they matter, which is why lossy WebP often manages smaller files than JPEG for photographs. How much smaller depends on the image and the encoder, so test your own files.

Lossless WebP: VP8L

The lossless codec is a separate design, not a gentler setting of the lossy one. Every pixel decodes back exactly. It combines several transforms before entropy coding:

  • Predictor transform. Each pixel is predicted from neighbours, and only the difference is stored. Smooth areas produce differences close to zero.
  • Colour transform. Correlation between red, green and blue is reduced so that fewer bits are needed for the remaining signal.
  • Subtract green. Green is subtracted from red and blue, a cheap decorrelation step that helps many images.
  • Colour indexing. Images with few distinct colours can be stored as a palette plus indices.
  • Backward references. Repeated pixel runs are encoded as pointers to earlier data, similar in spirit to LZ77 dictionary coding, and there is a local cache of recently used colours.
  • Entropy coding. Huffman codes with several tables are chosen for different parts of the image.

Lossless WebP suits graphics, screenshots and images with flat colour. The PNG equivalent is described in How PNG Compression Works.

Transparency

WebP stores alpha as a separate channel. In a lossless file, alpha is part of the pixel data. In a lossy file, the colour part uses the VP8 path while the alpha plane is stored in its own chunk, which can be compressed losslessly or with some quantisation. This is a notable difference from JPEG, which has no alpha at all, and from PNG, which cannot make a lossy transparent photo. It also means a lossy WebP with transparency can mix lossy colour with an exact alpha mask. One consequence: the soft edge of a cut-out photo can be kept without a matte colour baked in.

Animation

An animated WebP stores a sequence of frames in the container, each with a position, duration and blending rules. Frames can be lossy or lossless, and encoders can store only the changed rectangle of each frame. It is a practical replacement for animated GIF, which is limited to a 256-colour palette per frame. For long clips with real motion, a video format is still the better tool because video codecs use motion compensation across frames, which animated WebP does not.

Format Limits Worth Knowing

  • Image dimensions are capped at 16383 pixels per side.
  • Lossy WebP always uses 4:2:0 colour sampling, so very fine saturated colour detail can look softer than in a 4:4:4 JPEG.
  • Lossy and lossless are different codecs, so converting a PNG to lossy WebP changes pixels, while converting it to lossless WebP does not.
  • Converting an existing JPEG to lossy WebP re-encodes already lossy data, which adds a second layer of loss.

Browser support: all current major browsers (caniuse).

Where Encoder Settings Fit

The same file can be written with a quick or a slow search for the best predictions. Slower effort settings usually yield a smaller file at the same visual result, at the cost of encode time. Quality in lossy mode controls the quantiser; in lossless mode, effort controls how hard the encoder searches, and the picture does not change. Some tools also offer a near-lossless mode, which adjusts pixel values slightly before lossless coding to improve compression.

What This Means for Your Images

  • Photographs usually belong in lossy WebP.
  • Screenshots, logos and UI artwork usually belong in lossless WebP, or PNG if broad tool support matters.
  • Transparent photos are a good use of lossy WebP with alpha.
  • Short animations can replace GIF, but long video should stay as video.

For browser support, current Chrome, Firefox, Safari and Edge all support WebP. Workflow, fallbacks and markup are covered in the WebP Optimization Guide.

Try WebP on Your Own Files

Use the WebP compressor to compare sizes and look at the before and after view. You can upload up to 5 files per batch, choose Lossless, Lossy (quality default 85) or Custom, and download results individually or as a ZIP. Files are uploaded over HTTPS and deleted automatically after processing. No registration is required.

compress webp →