keepcalculator

06 Numbers and Powers

Container Formats vs Codecs: What’s the Difference?

Card No. 06·49494 · Updated · Standard formula, shown below

Duration 100.00 min
File size
100 MB
You entered
Total bitrate
8 Mbps
You entered
You enter
File size, Total bitrate
You get
Duration
Rounding
2 dp

Container formats and codecs are two distinct layers of a digital video or audio file: the container is the wrapper that holds the data, while the codec is the algorithm that compresses and decompresses the actual audio and video streams. When someone asks “container formats codecs?” they’re usually trying to understand how these two relate—and why a file’s extension (.mp4, .mkv) doesn’t tell you what codec is inside. This article explains the difference, why it matters, and how to choose the right combination for your needs.

Formula

The calculator above estimates how long a video file can be given its size and total bitrate. The formula is:

Duration (minutes) = (File size in MB × 8) / (Total bitrate in Mbps)

Where:

  • File size – the size of the whole file, in megabytes (MB).
  • Total bitrate – the sum of video and audio bitrates, in megabits per second (Mbps).
  • Duration – the playback time in minutes.

The factor of 8 converts megabytes to megabits (1 byte = 8 bits). This gives a rough estimate—real files have container overhead and variable bitrate, so actual duration may differ slightly.

Worked Example

Using the default values from the calculator:

  1. File size = 100 MB
  2. Total bitrate = 8 Mbps
  3. Convert file size to megabits: 100 × 8 = 800 Mb
  4. Divide by bitrate: 800 / 8 = 100 minutes

The result is 100 minutes, matching the calculator’s output. This means a 100 MB file at 8 Mbps will play for about 1 hour 40 minutes.

What Is a Container Format?

A container format is like a suitcase that holds multiple streams of data—video, audio, subtitles, and metadata (like chapter markers or cover art). The container does not compress anything; it simply organizes the streams and tells the player how to sync them. Common container formats include:

  • MP4 – the most widely supported, used by YouTube, smartphones, and streaming services.
  • MKV (Matroska) – a flexible, open-source container that supports virtually any codec and many subtitle tracks.
  • AVI – an older Microsoft container, still used but with limited codec support.
  • MOV – Apple’s QuickTime container, common in professional video editing.
  • WebM – designed for web video, typically paired with VP9/AV1 codecs.

What Is a Codec?

A codec (coder-decoder) is the algorithm that compresses raw video or audio into a smaller size and decompresses it for playback. Without a codec, a one-minute 1080p video would be several gigabytes. Codecs reduce that by removing redundant data (spatial compression) and changes between frames (temporal compression). Common video codecs:

  • H.264 (AVC) – the most compatible codec, used in MP4 and MKV files, supported by almost every device.
  • H.265 (HEVC) – the successor to H.264, offering better compression at the cost of higher CPU usage and licensing fees.
  • VP9 – Google’s open codec, used in WebM and YouTube.
  • AV1 – the newest open codec, royalty-free, with even better compression but slower encoding.

Audio codecs include AAC (standard in MP4), MP3 (older), Opus (excellent for streaming), and FLAC (lossless).

How Container and Codec Work Together

When you play a file, the player first reads the container to locate the streams, then uses the appropriate codec to decode each stream. The container must support the codec—not every container can hold every codec. For example:

  • MP4 officially supports H.264, H.265, and AAC, but not VP9 or Opus.
  • MKV can hold almost anything, including H.264, H.265, VP9, AV1, and any audio codec.
  • WebM only supports VP8/VP9/AV1 video and Opus/Vorbis audio.

If you try to put a VP9 video in an MP4 container, most players will fail to play it. That’s why you often see files with the same .mp4 extension but different codecs—the extension only tells you the container, not the codec.

Why the Confusion Happens

People often say “MP4 file” when they mean “H.264 video,” but MP4 is just the container. The confusion is understandable because most MP4 files use H.264, and most players handle them seamlessly. However, you can have an MP4 with H.265, or an MKV with H.264. The mismatch becomes a problem when you try to play a file on a device that doesn’t support the codec—even though the container is fine. For instance, older TVs may play .mp4 files but only with H.264, not H.265. Checking the codec is essential when a file won’t play.

How to Choose a Container and Codec

Your choice depends on your goal:

  • For maximum compatibility (uploading to social media, playing on any device): Use MP4 with H.264 and AAC. This is the safest combination.
  • For archiving or editing (keeping quality, multiple subtitles): Use MKV with H.265 or AV1, or even lossless codecs like FFV1. MKV preserves extra data well.
  • For web streaming (low bandwidth, fast loading): Use WebM with AV1 or VP9, or MP4 with H.264 if you need older browser support.
  • For small file sizes (storing lots of video): Use H.265 or AV1 in MKV, but be aware of encoding time and device support.

When converting files, you can often keep the same container and change only the codec, or vice versa. Tools like HandBrake or FFmpeg let you choose both separately.

Common Problems and Misconceptions

“Why won’t this MKV play on my TV?” – The TV’s player may not support the codec inside, not the container. Check the codec and convert to H.264 if needed.

“Is MP4 better than MKV?” – Not inherently. MP4 is more compatible; MKV is more flexible. Neither is “better” without context.

“Does changing the extension change the codec?” – No. Renaming a .mkv file to .mp4 does not change the codec; it only confuses players. You must re-encode the video to actually change the codec.

“Why is my file so large?” – Large files usually mean a high bitrate or a less efficient codec. Re-encoding with H.265 or AV1 can reduce size, but may lose quality if settings are wrong.

Frequently Asked Questions

What does “codec” stand for?

Codec stands for “coder-decoder” (or “compressor-decompressor”). It’s the software or hardware that compresses video/audio for storage and decompresses it for playback.

Can I play any codec in any container?

No. Each container has a list of codecs it officially supports. MKV is the most permissive, but MP4 and WebM are stricter. If a codec isn’t supported, the file won’t play or will have no audio/video.

How do I check what codec a file uses?

On Windows, right-click the file, go to Properties, then the Details tab—look for “Video codec” and “Audio codec.” On macOS, use the “Get Info” window. MediaInfo is a free tool that shows full details.

Is H.265 always better than H.264?

H.265 compresses about 50% better at the same quality, but it requires more processing power to decode and may have licensing costs. For personal use, H.264 is often still the practical choice for compatibility.

Why do some files have .mp4 but won’t play on my phone?

Your phone’s player may not support the codec inside (e.g., H.265 on an older phone). The container is fine, but the codec is unsupported. Convert the video to H.264 to fix it.

What is a “lossless” codec?

A lossless codec compresses without losing any data, so playback is identical to the original. Examples are FLAC for audio and FFV1 for video. These files are much larger than lossy codecs like H.264.

Final Advice

Understanding the container-codec distinction saves you from countless playback headaches. Always check the codec before converting or sharing a file, and choose the combination that matches your target device. For most everyday use, MP4 + H.264 + AAC remains the gold standard for compatibility, while MKV + H.265/AV1 is the choice for quality and flexibility.

Related

Formula used
in file_size | File size | MB | 100 | 0 | 100000
in bitrate | Total bitrate | Mbps | 8 | 0 | 1000
out duration | Duration | min | file_size * 8 / bitrate | 2

Each line is one input (in, sel, list) or one result (out: label, unit, formula, decimals). How the calculators work

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.

More cards in this drawer

The whole Numbers and Powers drawer →