Zig-zag scan is the specific path the encoder uses to read out the coefficients of a transformed block — starting at the top-left corner and zig-zagging diagonally to the bottom-right. The point: after the DCT, the top-left coefficient holds the most important information (the average brightness of the block), the values near it hold the next-most-important (broad shapes), and the bottom-right values hold the least important (the finest detail). Zig-zag scan turns the 2D block into a 1D sequence that puts important values first and unimportant values last.

This ordering is crucial for compression efficiency. After quantization, most of the high-frequency coefficients in the bottom-right round to zero. By scanning zig-zag, those zeros all end up at the end of the sequence, forming a long run that run-length coding compresses to almost nothing. If you scanned the block in row-major order instead, the zeros would be scattered through the sequence and run-length coding wouldn't have anything to compress. The simple geometric trick of changing the reading order is what makes the rest of the pipeline efficient.

For a product team, zig-zag scan is invisible plumbing inherited from JPEG. There's nothing to configure. Modern codecs (HEVC, AV1, VVC) actually use more sophisticated scan patterns — vertical-first or horizontal-first or even adaptive based on the dominant edge direction in the block — but the underlying idea is the same: arrange the coefficients so that the runs of zeros are as long as possible at the end. It's a small piece of the encoder pipeline, but a piece that everything downstream depends on.

Book cover: Video Encoding, Volume 1 of the Fora Soft Video Engineering Handbook

The book · Volume 1 of 7

Video Encoding: A Complete Guide to Video Compression — From Pixels and Color to H.264, HEVC, AV1, Quality Metrics, and AI

Zig-zag scan puts the important coefficients first so the long tail of zeros codes cheaply. Volume 1 covers zig-zag scan in detail: coefficient reordering, diagonal and other scan patterns in HEVC and AV1, run-length coding, and the handoff to entropy coding. Written by Nikolay Sapunov, CEO at Fora Soft.

Read it on Amazon →Kindle & paperback · Fora Soft Video Engineering Handbook

Building a custom encoder or analysis tool and need the coefficient path explained?

Tell us what you are building: we review your design from transform to entropy coding and point out where bits and compute can be saved. 250+ video products shipped since 2005.

Book a 30-min call →WhatsApp →Email us →