H.264 Is Magic: Why the Codec You Ignore Is the Hardest Software You'll Ever Run

5 min read 1 source explainer
├── "H.264 is a quietly miraculous engineering achievement that most developers take for granted"
│  ├── Sid Bala (sidbala.com) → read

Bala walks through the raw math — a 1080p60 stream is ~2.98 Gbps uncompressed, yet Netflix delivers perceptually identical video at ~5 Mbps, a 600× compression ratio. He argues this shouldn't be possible on paper, and the fact that it works everywhere invisibly makes H.264 the most under-appreciated piece of infrastructure most developers rely on daily.

│  └── @ea016 (Hacker News, 229 pts) → view

By resurfacing the 2016 post and driving it to 229 points, the submitter signals that the awe-at-H.264 framing still lands with a fresh generation of developers who've never looked under the hood of the codec they use constantly.

└── "H.264's genius is the bitstream spec, not any single algorithmic invention"
  └── top10.dev editorial (top10.dev) → read below

The editorial argues that macroblocks, DCT, motion compensation, quantization, and entropy coding were all pre-existing ideas. H.264's real achievement was packaging them into a decoder-permissive bitstream spec that let twenty years of encoder implementers (x264, QuickSync, VideoToolbox, NVENC) keep extracting quality gains without breaking backward compatibility.

What happened

A 2016 blog post by Sid Bala titled *H.264 Is Magic* keeps resurfacing on Hacker News — this latest round pulled 229 points — because every few years a new generation of developers runs the same back-of-the-envelope math and has the same reaction: this shouldn't work. The post walks through the arithmetic bluntly. A single uncompressed 1080p frame at 24-bit color is roughly 6 MB. At 60 fps that's about 2.98 Gbps of raw pixel data per second. Your Netflix stream delivers something perceptually indistinguishable at around 5 Mbps — a compression ratio north of 600× in the best case, and still ~150× for a mid-bitrate 1080p file.

H.264, formally ITU-T H.264 / MPEG-4 Part 10 / AVC, was finalized in 2003 by the Joint Video Team of ITU-T VCEG and ISO/IEC MPEG. Twenty-plus years later it is still the default codec of the open internet. YouTube re-encodes to it. Zoom, Teams, Meet, FaceTime, and every ring-doorbell and dashcam on earth lean on it. The reason the post keeps going viral isn't nostalgia — it's that most working developers have never actually looked under the hood of the one piece of software they rely on more than TCP.

The short version of what's happening inside the encoder: the picture is sliced into 16×16 macroblocks; each block is predicted from neighboring blocks (intra) or from a previously-decoded frame via motion vectors (inter); the residual error is run through an integer discrete cosine transform, quantized aggressively in the high-frequency bins the eye can't see, then entropy-coded with CABAC. A deblocking filter smooths the macroblock seams on the way out. None of these ideas are H.264's invention. H.264's achievement is that it packaged them into a bitstream spec permissive enough that twenty years of encoder implementers — x264, Intel QuickSync, Apple's VideoToolbox, NVENC — could keep squeezing quality out without breaking a single existing decoder.

Why it matters

The reason H.264 feels like magic is that it's one of the last widely-deployed pieces of software whose core assumption is that your users' eyeballs are the API. Almost everything else we ship assumes a deterministic consumer: a browser, a kernel, another service. Video codecs assume a wet, lazy, pattern-matching biological sensor, and they exploit it with surgical precision. Chroma subsampling (4:2:0) throws away 75% of the color information because the human retina has roughly ten times as many luminance-sensitive rods as color-sensitive cones in the periphery. The quantization matrix in the DCT step is literally shaped by psychovisual experiments from the 1970s. The deblocking filter exists because the eye is extraordinarily good at spotting straight-line artifacts and bad at spotting gradient ones.

Compare this to what the industry has tried to replace it with. H.265/HEVC, finalized 2013, gets you roughly 50% better compression at equal quality — and ten years in, it still has a patent-pool problem so ugly that Mozilla, Google, Netflix, Amazon, Intel, and others founded the Alliance for Open Media in 2015 largely to route around it. AV1, AOM's answer, finally shipped a stable spec in 2018, and in 2026 is still rolling out in anger because hardware decode blocks lag silicon cycles by years. The lesson every new codec learns the hard way: compression ratio is the easy part, deployment is the mountain. H.264 won not because it was the best math on paper but because it got into silicon early, got into Flash Player in 2007, got into the iPhone the same year, and never let go.

There's a quieter story in the comment thread worth sitting with. Several veterans point out that H.264 is probably the most expensive piece of free software you've ever used — not in dollars but in brainpower. The reference encoder, x264, has had somewhere north of a decade of full-time contributions from a small cadre of absolute obsessives (Jason Garrett-Glaser's early blog posts on x264 are still some of the best writing about performance work on the internet). Every 1% quality-per-bitrate improvement past the 2010 baseline took person-years. This is what mature software looks like: boring on the outside, bottomless on the inside, and economically irreplaceable precisely because nobody has the appetite to rewrite it.

The other thing the post surfaces, almost accidentally, is how badly modern engineering intuition handles problems with no clean abstraction boundary. H.264 is leaky by design. The encoder and decoder are coupled through psychovisual assumptions, through the specific quantization tables, through the exact behavior of the deblocking filter at macroblock edges. You cannot swap one piece without the whole system degrading. Developers trained on microservices and clean interfaces look at this and recoil. But a lot of the hardest problems in computing — codecs, databases, kernels, allocators — look exactly like this up close. The abstraction is a lie we tell ourselves on the way to the API.

What this means for your stack

If you're shipping video in 2026, the practical calculus has barely moved. Default to H.264 for compatibility, add an H.265 or AV1 track for the clients that have hardware decode, and let adaptive bitrate pick for you. Netflix's own 2022 engineering post on per-title encoding is still the right mental model: the codec is a knob, not a religion. If your traffic skews toward iOS 14+ and modern Android, you can push HEVC harder. If you're serving a long tail of smart TVs, embedded browsers, and five-year-old laptops, H.264 is still the only codec that is actually everywhere.

For WebRTC and real-time video, the picture is messier. H.264's baseline profile is the lingua franca of SFUs and MCUs because it's the one codec everything negotiates. VP8/VP9 are fine in Chrome-to-Chrome paths. AV1 real-time encode is finally viable on modern Intel and Apple silicon but still a CPU hog on anything older. If you're building a Zoom competitor, the realistic answer is still simulcast H.264 with an AV1 fast path for the top-tier clients — and a lot of engineering around packet loss concealment, which, incidentally, is another place where H.264's error-resilience features (SPS/PPS, slice groups, redundant pictures) quietly carry you.

The deeper takeaway for engineers who don't work on video: the next time you're tempted to rewrite something because the code is ugly, go read the x264 commit log first. Twenty years of someone being smarter than you in a very specific direction is not a cost you can casually eat. The parts of the stack that feel like magic are usually the parts where the magic is paid for upfront, in math, by people who are not coming back.

Looking ahead

The AV1 rollout will keep grinding forward — YouTube is already serving a meaningful share of its traffic in AV1 on supported devices, and the 2024-2025 wave of phones finally shipped hardware decode as table stakes. But H.264 isn't going anywhere this decade. It's the TCP of video: an aging, patent-encumbered, aesthetically compromised standard that works on literally every device you can name, and that's the only metric that has ever mattered in codec adoption. If you want to understand how real software ages gracefully, spend an afternoon with the spec. It's 800 pages of other people's cleverness, and almost none of it is on your résumé.

Hacker News 387 pts 143 comments

H.264 Is Magic (2016)

→ read on Hacker News
tgtweak · Hacker News

Had the pleasure of working with Jason Garrett-Glaser (better known as DarkShikari) circa 2011 on a patch for x264 to better utilize more cores (slice-threaded lookahead). At the time he was working with Sony to optimize their PlayStation game streaming service, and this had the potential to lower e

pwython · Hacker News

Ten years later, 2026 magic: AV1https://engineering.fb.com/2026/06/22/video-engineering/adop...And soon AV2https://av2.aomedia.org/

Dwedit · Hacker News

One uncommonly used feature of H.264 is support for lossless video. It's a bit hard to use due to tooling (not easy to discover and select the feature), and is sometimes incompatible with web browsers, but you can get actual lossless video using a mainstream video codec. You can verify that it

Hasz · Hacker News

I really like the idea that compression is intelligence, there are so many tricks an interesting ideas related to it. A bunch of them are described in the article, but you can imagine a long tail of many more inscrutable tricks chained together to get really incredible shrinkage in data.Hutter prize

HelloUsername · Hacker News

Previous discussions:4.nov.2016 https://news.ycombinator.com/item?id=12871403 219 comments17.mar.2022 https://news.ycombinator.com/item?id=30710574 219 comments24.may.2019 https://news.ycombinator.com/item?id=19997813 180 comments14.jun.2024 https:/&

// share this

// get daily digest

Top 10 dev stories every morning at 8am UTC. AI-curated. Retro terminal HTML email.