Run-length coding is the simple compression technique of replacing a run of identical consecutive symbols with a single (symbol, count) pair. "AAAAA" becomes "(A, 5)". It's the most ancient and least sophisticated of the entropy-coding family, dating to telegraph protocols in the 1960s, but it survives inside modern video codecs because it works perfectly on one specific pattern: long runs of zeros.

The reason this matters: after the DCT transform and quantization stages, most coefficients in a typical block round to zero. A typical 8×8 block of quantized coefficients might have 2 or 3 meaningful values in the top-left corner and 60-plus zeros filling the rest. Storing each zero individually would waste tremendous space. Storing them as "62 zeros" takes a handful of bits. Combined with zig-zag scan ordering (which arranges the 8×8 block into a 1D sequence that puts likely-nonzero values first and the long zero tail last), run-length coding packs the typical block into a strikingly small number of bits.

For a product team, run-length coding is invisible plumbing — there's no knob to tune — but it explains a structural fact about video compression: higher quantization (more aggressive compression) produces longer zero runs, which compress to almost nothing. That's why halving a video's bitrate doesn't usually halve its file size by half the same factor everywhere; the compression isn't linear because the run-length stage gets dramatically more efficient as quantization gets coarser. Modern codecs (AV1, HEVC, VVC) generalise the idea with arithmetic coding that handles arbitrary distributions even more compactly, but the underlying intuition — "long runs of zeros, compressed essentially for free" — is the same.

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

Run-length coding is why the long tails of zeros after quantization cost almost nothing to store. Volume 1 covers run-length coding in detail: zig-zag scan and coefficient reordering, run-level pairs, and how it hands off to entropy coding with CAVLC, CABAC and AV1's arithmetic coder. Written by Nikolay Sapunov, CEO at Fora Soft.

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

Building or debugging a codec pipeline and want to see where run-length coding fits?

Tell us what you are building: we walk your team through the coefficient coding path and point to where bits are spent and where they can be saved. 250+ video products shipped since 2005.

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