What is a codec?
A codec is a matched pair of programs. The coder turns pictures or sound into a compact bitstream, and the decoder turns that bitstream back into pictures or sound. A codec is a method, not a file type. The file type (MP4, WebM, MKV) is the container that holds the bitstream.
This page doesn't just describe codecs. It runs your browser's own encoders on a clip it generates, measures every frame they write, opens up the 8×8 block maths that JPEG and most video codecs share, and asks your device which codec and container combinations it can actually play.
The page draws a 3-second, 320×180 clip at 30 fps and gives it to your browser's video encoder (WebCodecs). Each bar is one frame the encoder actually wrote: tall purple bars are key frames, which contain the whole picture; short lilac bars are delta frames, which only describe what changed. Every frame is then decoded again and compared with the original.
JPEG, MPEG-2, H.264, HEVC, VP9 and AV1 all do the same core step. They turn a block of pixels into frequencies (a discrete cosine transform), divide each frequency by a step size, and round. Rounding is the only lossy part. Large step sizes for high frequencies erase fine texture; the encoder then stores the few numbers that aren't zero. This lab runs the real JPEG maths (ITU-T T.81 Annex K luminance table, IJG quality scaling) on a 64×64 patch. Click a block to open it.
A container decides how tracks are packed, timed and labelled. The codec decides how the pictures and sound inside are compressed. Each container specification lists which codecs it may carry, and each device decides which of those it can decode. This table puts both questions to your browser at once: grey cells are combinations the container's spec doesn't allow, the rest are your browser's real answers.
A format (like MP4) is the container that holds the data. A codec (like H.264) is how the video/audio data inside is compressed.
YouTube primarily uses H.264 for HD video and is transitioning to AV1 for better compression. Audio is usually AAC.
Use VLC media player: right-click the playing video > Tools > Media Information > Codec tab.
Without the correct codec, your device cannot decode the video and it will not play. VLC media player includes most codecs built-in.
H.264 for compatibility. H.265 for efficiency on modern devices. AV1 for the best compression on web platforms.