Decoding a PNG, byte by byte, from chunk headers to Adam7 interlacing

Each step of decoding a PNG (2022)

A walkthrough of the full PNG decoding pipeline: how chunks are structured and named, why the IDAT data is concatenated and decompressed with plain zlib, how per-line filters are undone, and how Adam7 interlacing splits an image into seven progressive passes. The example image's filter usage is tallied, and a deliberately introduced overflow bug shows what breaks when the Average filter is mishandled.

It looks like random noise, and that means that the compression algorithm did a good job.

More from this day

2026-10-18