A file called holiday.mp4 is described as "H.264." Which of the two is the format? Both are, but they name different layers. MP4 is a container, a file format that holds several streams together. H.264 is a codec, the method used to encode one of those streams.
Once you can tell the layers apart, a file's extension stops being confusing. This guide defines each layer, shows where MP4, MKV and WebM fit, explains why the same codec can live in different containers, and spells out which layer sets the file size.
Two layers in every media file
MDN's container guide defines a media container as a file format that encapsulates one or more media streams, such as audio or video, along with metadata, so they can be stored and played back together. It adds that a media file is defined by several components: the audio and video codecs, the container, and optionally subtitle codecs or metadata.
The Matroska specification, RFC 9559, is blunter. A container is not a video or audio compression format. It is an envelope in which there can be many audio, video and subtitle streams.
| Layer | What it is | What it decides | Examples |
|---|---|---|---|
| Codec | A method that encodes (and decodes) one stream | How the stream is compressed, and so how many bits per second it needs | AVC (H.264), VP9, AV1; AAC, Opus, MP3, FLAC |
| Container | A file format that packages streams and metadata | How streams, track information and metadata are arranged in one file | MP4, MKV (Matroska), WebM |
One file can therefore hold a video stream, two audio streams with different languages and a subtitle track, each recorded as its own stream. Matroska's track information stores the language and the type of each track. For a closer look at the first layer, read what is a codec.
What MP4, MKV and WebM are
All three are containers. The documentation describes them differently.
| Container | What the documentation says | Codecs the documentation lists |
|---|---|---|
| MP4 | MPEG-4 Part 14, derived from the ISO base media file format (MDN). RFC 4337 describes MP4 as a standard file type for encapsulating ISO/IEC 14496 data. | Video, among others: AVC (H.264), AV1, VP9. Audio: AAC, FLAC, MP3, Opus. |
| MKV | The Matroska container, defined in RFC 9559. Each track records its type (audio, video, subtitles) and identifies the codec that decodes it. | Each track names its own codec. |
| WebM | A format based on Matroska and designed for modern web environments (MDN). | Video: AV1, VP8, VP9. Audio: Opus, Vorbis. |
These lists show what the documentation names, not every combination that can exist. MDN also notes that compliant WebM implementations must support the VP8 and VP9 video codecs and the Vorbis and Opus audio codecs, and that any other codec may require a license.
Same codec, different containers
The relationship runs both ways. MDN's video codec guide lists the containers that can hold each codec. VP9 appears with MP4, Ogg and WebM. AV1 appears with ISOBMFF, MPEG-TS, MP4 and WebM. AVC appears with 3GP and MP4. So one encoded video can be packaged in several containers, and one container can hold several codecs.
That is why an extension does not name the codec. MDN gives two examples. An Ogg file that holds only an Opus audio track is sometimes called an Opus file, but it is still an Ogg file. An MP3 file is a stream of MPEG-1 Audio Layer III frames, often with metadata tags, and it is not stored in a conventional container at all.
Audio codecs follow the same pattern. RFC 9639 explains that FLAC frames can be placed in other containers as they are, with the container handling features such as combining audio with video. Lossless and lossy audio formats compares FLAC with the formats that are not lossless.
What this means for file size
Most of a video file's size comes from its streams, so the codec settings do the work. The estimate is the combined bitrate times the duration:
bytes = (video bitrate + audio bitrate) × seconds ÷ 8
Worked example. Example: a 10-minute video with video at 5 Mbps and audio at 128 kbps, which is 600 seconds.
- Total bitrate: 5,000,000 + 128,000 = 5,128,000 bit/s.
- Bits: 5,128,000 × 600 = 3,076,800,000 bits.
- Bytes: 3,076,800,000 ÷ 8 = 384,600,000 bytes, or 384.6 MB (decimal: 1 MB is 1,000,000 bytes).
The container adds its own structure and metadata on top of this. RFC 8216 notes that a segment's bit rate includes container overhead. The amount varies with the file, so the video file size calculator treats the result as an estimate. How to calculate video file size from bitrate and duration walks through the full method.
Because a container packages streams that are already encoded, moving the same streams into another container changes the packaging and not the encoded bits. Changing the codec or the bitrate is what changes the size. What is bitrate explains the second of those.
Common mistakes
- Calling MP4 a codec. MP4 is a container. The video inside it is encoded by a codec such as AVC or AV1, and the audio by another.
- Reading the extension as the codec. An extension names the container, and sometimes a codec and container pair that became common. It does not tell you which codec encoded each stream.
- Expecting a container change to improve quality. The container packages streams. Quality depends on the codec and the bitrate used to encode them.
- Assuming every container accepts every codec. WebM, for example, has a list of required codecs, and MDN says others may need a license.
- Leaving the audio and extra tracks out of a size estimate. A file can hold several audio streams and subtitle tracks. Add each stream's bitrate.
FAQ
Is MP4 a codec?
No. MP4 is a container format. The streams inside an MP4 file are encoded by codecs such as AVC (H.264), AV1 or VP9 for video and AAC or Opus for audio.
Is MKV better than MP4?
Neither container sets quality, because that comes from the codecs and bitrates inside. RFC 9559 stresses that Matroska holds many audio, video and subtitle streams in one file. MDN describes MP4 as supporting several of the most-used codecs. Choose by the streams you need to store.
Does the container change the file size?
Only slightly. The container adds metadata and structure, while the bulk of the size comes from the encoded streams. The bitrate and the duration drive the estimate.
What is WebM?
WebM is a container based on Matroska and designed for modern web environments, according to MDN. It uses video codecs such as VP8, VP9 and AV1 and audio codecs such as Vorbis and Opus.
Sources
- MDN Web Docs, Media container formats (file types). Accessed November 6, 2026.
- IETF, RFC 9559: Matroska Media Container Format Specification. Accessed November 6, 2026.
- MDN Web Docs, Web video codec guide. Accessed November 6, 2026.
- IETF, RFC 4337: MIME Type Registration for MPEG-4. Accessed November 6, 2026.
- IETF, RFC 8216: HTTP Live Streaming. Accessed November 6, 2026.
- IETF, RFC 9639: Free Lossless Audio Codec (FLAC). Accessed November 6, 2026.



