PNG Filters Explained: What Sub, Up, Average, and Paeth Do Before Compression

Rows of colored squares flow into a compact cube made of neatly stacked colored blocks.

PNG filtering does not blur an image. It transforms scanline data so Deflate can compress predictable patterns more effectively.

Illustrative editorial image generated with AI.

PNG filtering does not blur an image. It transforms scanline data so Deflate can compress predictable patterns more effectively.

Filter does not mean Photoshop filter

PNG's filter stage is reversible preprocessing. The decoded pixel values are reconstructed exactly. The purpose is to turn neighboring-pixel relationships into byte patterns that the compression stage can encode efficiently.

The five choices

Filter type 0 is None. These operations work on bytes: Sub uses the corresponding byte of the prior pixel, Up the corresponding byte in the previous scanline, Average the integer average of left and above, and Paeth selects from left, above and upper-left using its predictor. The encoder stores a difference modulo 256; decoding reverses that operation. The encoder can choose a filter per scanline.

Why flat graphics and photos behave differently

A line of similar colors has strong local predictability, but so can a smooth photographic gradient. The best predictor varies with image structure. There is no single filter that wins for every row of every image.

Indexed PNG is a special case

The W3C specification recommends filter type None for indexed-color images in typical cases. For truecolor and greyscale, adaptive filter selection can improve compression when encoding time is less important.

Optimization can change bytes without changing pixels

Two encoders can choose different scanline filters and Deflate strategies yet reconstruct the exact same image. That is why a 'lossless optimized' PNG can have a very different byte stream from the original.

What to tune first

For most users, a reputable optimizer is better than manually forcing Paeth or Sub. If you operate a large image pipeline, benchmark representative assets: screenshots, icons, diagrams, and photographic PNGs can respond differently.

Sources and technical basis

Read the W3C PNG specification for the format definition. Check an exported file in the application that will actually use it; a format capability does not guarantee every application handles it identically.

Sources

Related