Container vs Codec: What's the Difference in Audio?
A codec compresses the audio; a container is the file that holds it. See which codecs fit in MP4, M4A, OGG, WAV and MKV, and how to fix files that will not play.
The quick answer
A codec is the method that compresses audio (or video) and decodes it again, such as AAC, MP3, Opus or FLAC. A container is the file format that holds the compressed stream plus tags, cover art and timing, such as MP4, M4A, OGG, MKV or WAV. One container can hold many codecs, so the file extension tells you the box, not what is inside it.
- Codec = the audio itself: it sets quality, file size and whether a device can decode it.
- Container = the box: it holds the stream, tags, cover art, chapters and seek data.
- Same box, different contents: .m4a can be lossy AAC or lossless ALAC; .ogg can be Vorbis, Opus or FLAC.
- Remuxing changes the box only and loses nothing. Re-encoding changes the codec and, for lossy targets, costs quality.
Do it in your browser — free, no upload
If a player has ever refused a file it claims to support, the cause is almost always the gap between the container and the codec. The two words get used as if they meant the same thing, but they describe different layers of a file. Once you can tell them apart, it is easy to see why an .ogg plays in VLC but not in an older phone app, why renaming .m4a to .mp3 breaks the file, and why some conversions are instant and lossless while others are not.
The short version
- Codec: the method that compresses the audio and decodes it again. Examples: MP3, AAC, Opus, Vorbis, FLAC, ALAC, PCM. It decides sound quality and file size.
- Container: the file format that wraps the encoded audio, along with tags, cover art, chapters and timing data. Examples: MP4/M4A, OGG, MKV, WebM, WAV, AIFF, CAF.
- The extension names the container, and even that is only a hint. It never guarantees which codec is inside.
Think of a container as a box with a label and a packing list. The codec is what is actually packed inside. A device has to open the box and understand what is inside it.
What a container does
A container holds one or more encoded streams and everything a player needs to use them:
- the audio stream (and, in a video file, the video and subtitle streams)
- a code saying which codec each stream uses
- tags such as title, artist and album, plus cover art
- timing and index data, so a player can jump to minute three without reading everything before it
- in some containers, chapters, multiple audio tracks or lyrics
The major containers are built in different ways. WAV uses RIFF "chunks": a format chunk that describes the audio, a data chunk that holds it, and optional metadata chunks. MP4 and its audio-only form, M4A, are built from nested "boxes" (also called atoms). The MP4 format extends the ISO base media file format, which is directly based on Apple's QuickTime format. Ogg splits data into numbered pages designed for streaming. Matroska (.mkv) is a flexible open format, and WebM is based on it.
What a codec does
A codec turns raw audio (PCM samples) into a compact stream and back again. Lossy codecs such as MP3, AAC, Opus and Vorbis drop detail you are unlikely to hear. Lossless codecs such as FLAC and ALAC keep every sample. The codec is what decides the things people actually care about: how it sounds, how big the file is, and how much delay there is. Our guide to what an audio codec is covers each codec and which one to choose.
Which codecs go in which container
| Container (extension) | Codecs you will usually find inside | Notes |
|---|---|---|
| MP4 (.mp4) | AAC; video files add H.264 or HEVC video | Can also carry MP3, ALAC, FLAC or Opus, which are less common |
| M4A (.m4a) | AAC (lossy) or ALAC (lossless) | Same MP4 format, used for audio-only files |
| M4B (.m4b) | AAC | Audiobooks and podcasts, with chapter markers |
| OGG (.ogg, .oga) | Vorbis, Opus, FLAC or Speex | .opus files are Opus in Ogg |
| WebM (.webm) | Opus or Vorbis | Based on Matroska, built for the web |
| MKV (.mkv) | Almost anything: AAC, AC-3, DTS, FLAC, Opus | Often several audio tracks in different languages |
| WAV (.wav) | PCM, almost always | Can also hold ADPCM, μ-law, A-law or even MP3 |
| AIFF (.aiff, .aif) | PCM | The AIFF-C variant can hold compressed audio |
| CAF (.caf) | Many, including ALAC and PCM | Apple's format, with no 4 GB size limit |
| FLAC (.flac) | FLAC | FLAC's own native container |
| MP3 (.mp3) | MP3 | The codec stream is, in effect, the file |
MP3 is the odd one out. An MP3 file is basically a sequence of MP3 frames with tags attached, so the codec and the file type share a name. That one case is why so many people assume every audio format works that way.
The extension only names the box
Because one container can hold different codecs, the extension can mislead you:
- .m4a may be lossy AAC or lossless ALAC. The files look alike in a folder, but the ALAC one is usually several times bigger.
- .ogg may be Vorbis or Opus. Android, for example, plays Vorbis in Ogg on every version but only plays Opus from Android 5.0.
- .mp4 may hold AAC audio, or a codec a simple audio player lacks, such as AC-3.
- .wav is almost always PCM, but an ADPCM or μ-law WAV will not open in some tools.
Renaming never converts a file. Changing song.m4a to song.mp3 only changes the label. The AAC data inside stays AAC, and a player that trusts the name will fail or play nothing. A real conversion decodes the old codec and encodes the new one.
How to see which codec is inside
- VLC: open the file, then choose Tools > Codec Information.
- MediaInfo: a free app for Windows, macOS and Linux that lists every stream with its codec, sample rate, bit depth and bitrate.
- ffprobe: the command-line tool that comes with FFmpeg. Run
ffprobe yourfile.m4aand read the Stream line. - Audio editors: most show source properties when you import a file.
What you find usually explains the problem. If an "MP4 with no sound" has AC-3 audio, the player lacks that decoder. If a "huge M4A" turns out to be ALAC, it is lossless rather than AAC.
Remuxing vs re-encoding
There are two very different ways to change a file's format.
Remuxing moves the encoded stream into a different container without touching it. It is fast and loses nothing. Examples include pulling the AAC track out of an MP4 into an M4A, or taking an Opus track out of a WebM. FFmpeg does this with the -c copy option, which means "copy the stream, do not re-encode."
Re-encoding decodes the audio and compresses it again, often with a different codec. It is slower, and if the new codec is lossy, it costs some quality each time. Going between lossless formats (WAV, AIFF, FLAC, ALAC) is exact as long as the bit depth and sample rate stay the same.
The rule: if the target device supports the codec you already have and only needs a different container, remux. Re-encode only when the codec itself has to change, and when you do, start from the best source you have.
Fixing "format not supported" errors
Work from the outside in:
- Container: does the player accept this file type at all?
- Codec: check what is inside, using one of the tools above.
- Player support: look for the list of codecs the device supports, not just file types. "Plays OGG" may mean Vorbis only.
- Convert if needed: MP3 is the safest choice for nearly any device, and AAC suits Apple hardware.
Typical fixes: an Opus .ogg on an older player becomes an MP3 with OGG to MP3. An ALAC .m4a on a device that only knows AAC goes through M4A to MP3. The audio from a video file comes out with MP4 to MP3 or MKV to MP3. These converters run in your browser with FFmpeg, so files are never uploaded. Free users get 5 conversions per month. The output is limited to the first 10 seconds as a preview, with a 20MB input file size limit. Upgrade to Pro for unlimited, full-length conversions.
Choosing a codec and container
Pick the codec first, then use the container that normally goes with it:
| Goal | Codec | Container |
|---|---|---|
| Play on almost anything | MP3 | .mp3 |
| Apple devices, small files | AAC | .m4a |
| Lossless in Apple's apps | ALAC | .m4a |
| Lossless archive | FLAC | .flac |
| Recording and editing | PCM | .wav or .aiff |
| Voice, calls, web audio | Opus | .opus, .ogg or .webm |
| Games and open-source projects | Vorbis | .ogg |
When the file is going somewhere specific, such as a podcast host, a video editor or a game engine, check what it asks for. Requirements are usually stated as a codec and a container together.