Softeem Emphasis

How to Choose the Right Image Format: WebP, AVIF, and PNG

By Softeem Engineering on October 7, 2026

Engineering Reference Visual Engineering
How to Choose the Right Image Format: WebP, AVIF, and PNG
#Image Codecs#WebP#AVIF#PNG#Compression#Rate Distortion

In modern web development, image optimization is frequently reduced to a blunt imperative: "Convert everything to WebP (or AVIF)." Build scripts automatically transcode entire asset directories, and audit tools issue generic warnings whenever a PNG file is detected.

Yet image codecs are not interchangeable compression utilities competing along a single dimension of file size. Each format represents fundamentally different assumptions about signal representation, redundancy reduction, mathematical transforms, and hardware decoding costs.

Choosing the right format requires understanding the mechanical trade-offs between lossless spatial filtering, block-based transforms, directional intra-prediction, and mobile CPU decode latency. These formats are not successive generations of the same technology; they occupy fundamentally different points in a multidimensional design space.


The Three Codec Paradigms

┌────────────────────────────────────────────────────────────────────────┐
│                      CODEC ARCHITECTURAL TAXONOMY                      │
├───────────────────┬───────────────────────────┬────────────────────────┤
│ PNG               │ WebP                      │ AVIF                   │
│ (ISO/IEC 15948)   │ (VP8 Keyframe Derived)    │ (AV1 Intra-Frame Tech) │
├───────────────────┼───────────────────────────┼────────────────────────┤
│ • Lossless Only   │ • Lossy & Lossless Modes  │ • Lossy & Lossless     │
│ • Spatial Filters │ • 16×16 & 4×4 Predictors  │ • Rich Directional Intra│
│ • Deflate Entropy │ • 4×4 Integer Transforms  │ • Recursive Partitions │
│ • 0 Decode Jitter │ • Ubiquitous HW Decoding  │ • 10/12-Bit Precision │
└───────────────────┴───────────────────────────┴────────────────────────┘

1. PNG: Lossless 2D Spatial Filtering & Deflate

PNG does not compress pixel values directly. Because adjacent pixels in natural imagery share high spatial correlation, PNG first applies one of five reversible scanline filters to each row:

  • None (00): Unmodified raw byte values.
  • Sub (11): Difference between the current pixel and the pixel to its left: x−ax - a.
  • Up (22): Difference between the current pixel and the pixel directly above: x−bx - b.
  • Average (33): Difference relative to the arithmetic mean of left and above: x−⌊(a+b)/2⌋x - \lfloor(a + b)/2\rfloor.
  • Paeth (44): Non-linear predictor choosing the closest neighbor (a,b, or ca, b, \text{ or } c) along local gradients.

Filtering transforms high-magnitude RGB amplitudes into a low-variance differential byte stream centered around zero. The filtered stream is then compressed using standard Deflate (a combination of LZ77 sliding-window dictionary substitution and Huffman statistical entropy coding).

Because PNG applies zero frequency quantization, it guarantees mathematical bit-identity: the decoded buffer matches the original sensor input byte-for-byte.

2. WebP: Macroblock Intra-Prediction & 4×4 Integer Transforms

Developed from Google’s VP8 video codec, lossy WebP treats an image as a single video keyframe.

Instead of filtering entire scanlines, WebP subdivides the image into 16×1616 \times 16 macroblocks and 4×44 \times 4 sub-blocks. For macroblocks, the encoder chooses from four spatial prediction modes (Vertical, Horizontal, DC average, and TrueMotion). At the 4×44 \times 4 sub-block level, the encoder can evaluate ten directional and planar predictors based on previously decoded neighboring boundary pixels.

The prediction residual is transformed into frequency space using a 4×44 \times 4 integer transform that closely approximates the Discrete Cosine Transform (DCT):

Y=C⋅X⋅CT,whereC=(646464648936−36−8964−64−646436−8989−36)Y = C \cdot X \cdot C^T, \quad \text{where} \quad C = \begin{pmatrix} 64 & 64 & 64 & 64 \\ 89 & 36 & -36 & -89 \\ 64 & -64 & -64 & 64 \\ 36 & -89 & 89 & -36 \end{pmatrix}

For 16×1616 \times 16 luma macroblocks, the sixteen DC coefficients from the sub-blocks undergo a secondary 4×44 \times 4 Walsh-Hadamard Transform (WHT) to further concentrate low-frequency energy before quantization. High-frequency coefficients are then divided by quantization step sizes and rounded, eliminating imperceptible visual redundancy while preserving dominant structural features.

3. AVIF: AV1 Intra-Frame Coding Tools

AVIF wraps the intra-frame encoding capabilities of the Alliance for Open Media (AOMedia) AV1 standard inside an ISO Base Media File Format (ISOBMFF) container. It provides a substantially richer set of prediction tools and spatial partitioning options than VP8:

  • Recursive Superblock Partitioning: While WebP is constrained to fixed 16×1616 \times 16 macroblocks, AVIF partitions images hierarchically into superblocks up to 128×128128 \times 128 down to 4×44 \times 4 sub-blocks via recursive quadtree and 1:2 / 1:4 rectangular splits, dynamically conforming to image complexity.
  • Expanded Directional Intra-Prediction: AV1 combines multiple nominal directional modes with fine angle deltas alongside non-directional predictors (Smooth, Paeth, and DC modes), accurately tracking continuous linear edges and eliminating staircasing artifacts along diagonal boundaries.
  • Chroma from Luma (CfL): Leverages the luminance (YY) channel's high-resolution structure to predict color chroma (U/VU/V) distribution across color planes.
  • Wide Bit-Depth Support (10-Bit & 12-Bit): While standard 8-bit channels represent 256 quantization levels, AVIF natively supports 10-bit and 12-bit coding. This higher bit depth substantially reduces visible quantization banding in subtle sky gradients, studio backdrops, and shadow roll-offs, especially under aggressive compression.

Quantifying Compression: Rate-Distortion Optimization

To objectively compare lossy codecs, signal processing engineers rely on Rate-Distortion Optimization (RDO): evaluating reconstructed image quality against byte budget.

       ▲ PSNR (dB) - Image Fidelity
       │
    40 ┼───────────────────────┈┈┈┈┈┈  (Visual Transparency Threshold)
       │                 .--- AVIF (Steep early climb, excellent low-bitrate fidelity)
    35 ┼           .---' 
       │     .---' .---- WebP (Smooth plateau, slight macroblock blur)
    30 ┼    / .---'
       │   / /
    25 ┼  / /    [ PNG = Fixed point at lossless bit-rate ]
       │ / /
       └─┴─┴──────┴──────┴──────┴──────► Bits Per Pixel (bpp) / Byte Weight
         0.2     0.5    1.0    2.0

Peak Signal-to-Noise Ratio (PSNR)

PSNR measures logarithmic reconstruction error relative to the maximum possible signal power:

PSNR=10⋅log⁡10(MAXI2MSE)\text{PSNR} = 10 \cdot \log_{10} \left( \frac{\text{MAX}_I^2}{\text{MSE}} \right)

Where MAXI=255\text{MAX}_I = 255 for 8-bit channels, and Mean Squared Error (MSE\text{MSE}) across an M×NM \times N raster is:

MSE=1M⋅N∑i=0M−1∑j=0N−1[I(i,j)−K(i,j)]2\text{MSE} = \frac{1}{M \cdot N} \sum_{i=0}^{M-1} \sum_{j=0}^{N-1} [I(i, j) - K(i, j)]^2

The Lagrangian RDO Cost Function

When tuning lossy parameters (such as quality sliders from 1 to 100), the encoder solves an optimization problem for each pixel block:

min⁡J(λ)whereJ(λ)=D+λR\min J(\lambda) \quad \text{where} \quad J(\lambda) = D + \lambda R

Where DD represents visual distortion (MSE or structural SSIM variance), RR represents the bit-rate cost, and λ\lambda acts as the Lagrange multiplier controlling the quality-versus-size trade-off.

Because AVIF features richer prediction tools and adaptive transform block sizes, its Rate-Distortion curve typically climbs steeper than WebP at low-to-medium bitrates (0.2 to 0.6 bpp0.2\text{ to }0.6\text{ bpp}). In many photographic workloads, AVIF can achieve comparable visual quality at substantially lower bitrates. This often yields 20% to 40% byte savings in standard photographic test sets, though the exact margin depends on target fidelity, image entropy, and encoder presets.


Alpha Transparency Architecture: Uncompressed vs. Auxiliary Streams

For UI components, product cutouts, and iconography, alpha transparency handling is paramount:

PNG Alpha Architecture:
[ Pixel Buffer: RGBA_8888 ] ──(Interleaved or Filtered)──► Single Contiguous Bitstream

WebP Alpha Architecture:
[ RGB Channels (VP8 Lossy) ] ──┐
                               ├──► RIFF Container Multiplexing
[ Alpha Plane (VP8L Lossless) ] ┘

AVIF Alpha Architecture:
[ Primary Item: YUV420 Image ] ──┐
                                 ├──► ISOBMFF Auxiliary Item Reference ('auxl')
[ Alpha Item: Monochrome Y Plane ]┘
  1. PNG Interleaved Alpha: PNG stores alpha directly inside the pixel byte stream (RGBA). Every pixel carries a true 8-bit alpha value (0 to 2550\text{ to }255). The Deflate engine compresses alpha using the same 2D spatial predictors as color channels.
  2. WebP Dual-Stream Multiplexing: In lossy WebP, the RGB color channels are encoded using lossy VP8, while the alpha channel is stripped and encoded using a separate, specialized lossless VP8L bitstream. The two streams are combined inside a RIFF container. This guarantees crisp, artifact-free cutouts even when the underlying RGB image is compressed.
  3. AVIF Auxiliary Alpha Plane: AVIF handles transparency by declaring an auxiliary monochrome image item (auxl) inside the MP4 container box. The auxiliary plane can be encoded losslessly or lossily with independent quantization parameters.

The Hidden Dimension: Decode Latency and Hardware Acceleration

Asset weight over the network is only half the web performance equation. Once an image arrives in the browser, device CPU cycles and RAM dictate how quickly the visual rasterizes onto the screen.

Asset Pipeline Latency:
Total Latency = Network Transfer Time + Container Ingestion + Decompression & Decode + GPU Texture Upload
Performance Factor PNG WebP AVIF
Encoding Speed Very Fast (O(N)O(N) filter + Deflate) Fast (Single-pass VP8) Moderate to Slow (Multi-mode search)
Decode CPU Cycles Minimal (Simple stream expansion) Low (Mature hardware decoders) Higher (Complex prediction syntax)
Hardware Support Universal (Every chip since 1996) Ubiquitous across desktop & mobile Rapidly expanding (~96% browser support)
Memory Buffer W×H×4 bytesW \times H \times 4\text{ bytes} W×H×4 bytesW \times H \times 4\text{ bytes} W×H×4 bytesW \times H \times 4\text{ bytes} (or 10-bit planar)
Optimal Use Case Screenshots, crisp line art, brand logos Broad web delivery, e-commerce SKUs Hero photography, rich studio gradients

While AVIF browser support is now near-universal (~96% global coverage), AVIF generally exhibits higher decoding complexity than WebP due to its rich prediction syntax and multi-scale transform pipelines. On modern devices with hardware AV1 support, this compute gap narrows significantly; however, on older or lower-power hardware relying on software decoders, CPU cycles during decoding can still impact main-thread responsiveness under rapid scrolling across dense image feeds. WebP, with simpler parsing syntax and widespread SoC hardware acceleration, provides an exceptionally lightweight decode profile across virtually any client environment.


The Modern Architectural Decision Framework

Rather than treating format selection as an absolute rule of thumb, visual engineering teams approach it as a workload-specific methodology: start with an informed baseline, and measure whenever the trade-off matters.

Content / Workload Recommended Starting Point Technical Rationale & Verification
Logos, line art, UI screenshots PNG (or Vector SVG) Avoids high-frequency transform ringing; preserves exact edge contrast.
General photographic web imagery WebP (Quality 80–85) Fast decode, universal hardware acceleration, predictable byte savings.
Bandwidth-critical hero photography AVIF (Quality 60–75) Superior RDO efficiency in low-to-mid bitrates; minimizes byte transfer cost.
Subtle gradients, HDR, wide color AVIF (10-Bit Depth) 10-bit quantization substantially reduces visible banding in delicate tones.
Exact sensor / pixel preservation PNG Mathematical bit-identity; lossless reversible spatial filtering.
Unknown or mixed asset catalog Benchmark representative samples Test candidate assets across formats to locate the empirical RDO sweet spot.

The Engineering Principle: Measure, Don't Guess

Format selection should not be governed by dogmatic build-time rules. A graphic with high spatial frequencies (such as a text-heavy user interface) often compresses smaller in PNG than in lossy WebP, while a 4K studio photograph can achieve substantially higher perceptual fidelity in AVIF at a fraction of the weight.

The engineering approach is straightforward: benchmark your actual assets against objective quality and delivery budgets.

Use Softeem's client-side converter to inspect, compare, and validate candidate formats with real-time quality tuning, dimensional scaling, and instant file size comparisons directly in your browser:

👉 Launch Image Format Converter

Interactive Implementation

Explore this technique with Softeem's Client-Side Image Format Converter

Convert between WebP, AVIF, PNG, and JPEG with precision quality controls.

Open Tool