← Back to blog

How Video Compression Works: H.264, H.265, VP9, and AV1

Published February 26, 2026 · 9 min read

Without compression, a single minute of 4K video would take over 20 GB of storage. Video codecs make streaming, sharing, and storing video practical by reducing file sizes by 100–1000×. Here's how they do it.

The Three Pillars of Video Compression

Every video codec exploits three types of redundancy to shrink data:

1. Spatial redundancy: Within a single frame, adjacent pixels are usually similar. Instead of storing each pixel individually, the encoder describes regions of similar color, texture, and pattern. A blue sky doesn't need millions of individual blue pixel values — just "this entire region is blue with slight gradient."

2. Temporal redundancy: Consecutive frames in video are nearly identical. Rather than encoding each frame from scratch, the encoder stores only what changed between frames. In a talking-head video, only the mouth and facial muscles move — the background is stored once and referenced for subsequent frames.

3. Perceptual redundancy: Human vision is more sensitive to brightness changes than color changes, and more sensitive to low-frequency detail than high-frequency detail. Encoders can aggressively compress aspects of the video that humans won't visually notice.

I-frames, P-frames, and B-frames

I-frames (Intra) are complete standalone images — like a JPEG. They're large but provide reference points.

P-frames (Predicted) only store differences from the previous frame. Much smaller.

B-frames (Bidirectional) reference both past and future frames for even better compression. They're the smallest but require more processing to decode.

A typical encoded video might have an I-frame every 2 seconds (the "keyframe interval") with P and B frames filling the gaps.

H.264 (AVC) — The Workhorse

Released in 2003, H.264 is still the most widely used video codec in the world. Every device, every browser, every platform supports it. It strikes an excellent balance between compression efficiency, encoding speed, and decoding complexity. For most use cases in 2026, H.264 remains the safe default.

H.265 (HEVC) — The 4K Standard

H.265 achieves roughly 40% better compression than H.264 at the same quality. This makes it essential for 4K and 8K content where file sizes would otherwise be impractical. The trade-off: encoding is significantly slower (2–10× depending on settings), and licensing was historically complex (though this has improved). Supported by most modern devices but not all web browsers.

VP9 — Google's Open Alternative

Developed by Google as a royalty-free competitor to H.265, VP9 offers similar compression efficiency. It's the primary codec used by YouTube for 4K content. VP9 is supported in all major browsers and most Android devices. Encoding is slower than H.264 but comparable to H.265.

AV1 — The Future

AV1 is the collaborative effort of the Alliance for Open Media (Google, Apple, Microsoft, Netflix, Amazon, and others). It delivers ~30% better compression than H.265/VP9 and is completely royalty-free. As of 2026, AV1 hardware decoding is built into most new devices and is used by Netflix, YouTube, and other streaming platforms.

The main downside: encoding is very slow — 5–20× slower than H.264. This limits its use to pre-encoded content rather than live streaming (though hardware encoders are improving rapidly).

Bitrate, Resolution, and Quality

Bitrate is the amount of data per second of video (measured in Mbps). Higher bitrate = higher quality but larger files. The "right" bitrate depends on resolution, content complexity, and codec:

ResolutionH.264H.265/VP9AV1
720p3–5 Mbps2–3 Mbps1.5–2 Mbps
1080p5–10 Mbps3–6 Mbps2–4 Mbps
4K20–40 Mbps12–20 Mbps8–14 Mbps

How to Compress Video Without Losing Quality

  1. Use the right codec: Switching from H.264 to H.265 alone can cut file size by 40% at the same visual quality.
  2. Use CRF encoding: Constant Rate Factor lets the encoder use more bits for complex scenes and fewer for simple ones. CRF 23 is a good default for H.264; CRF 28 for H.265.
  3. Don't upscale: If your source is 1080p, encoding at 4K just wastes bits. Match the output resolution to your source.
  4. Two-pass encoding: For the absolute best quality-to-size ratio, use two-pass. The first pass analyzes the video; the second encodes with optimal bit allocation.

Convert & Compress Video