Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

What Is a Codec? Definition, Types & How It Works

· 6 min read · Home Tech

In this article
  1. Where the Term Comes From
  2. How Codecs Work: Compression and Decompression
  3. Common Audio Codecs
  4. Common Video Codecs
  5. How to Choose a Codec
  6. Common Codec Problems and Fixes
  7. Codec vs. Container vs. Format
  8. Hardware vs. Software Codecs
  9. Frequently Asked Questions

A codec is software or hardware that compresses digital audio or video for storage or transmission and decompresses it for playback or editing. The word is a portmanteau of "coder-decoder" (and sometimes "compressor-decompressor"). Every video you stream, every song on your phone, and every video call you make relies on a codec. Without them, a single minute of 1080p video would take gigabytes of space and hours to download. This article explains what codecs actually do, the main types, how to choose one, and common problems you might run into.

Where the Term Comes From

The word "codec" was coined in the 1950s in the telecommunications industry, combining "coder" and "decoder." Early telephone systems used codecs to convert analog voice signals into digital data and back. The term later expanded to cover video and audio compression in computing. It is a standard technical term, not slang or informal. You will see it in official documentation, software settings, and hardware specs. A related term, "container," is often confused with a codec: the container is the file format (like MP4 or MKV) that holds the compressed streams, while the codec is the algorithm that does the compressing. For example, an MP4 file might contain H.264 video and AAC audio.

How Codecs Work: Compression and Decompression

Codecs reduce file size by removing redundant or imperceptible data. The compressed stream is called the "bitstream." When you play a file, the decoder reconstructs the original signal as closely as possible. There are two broad categories:

  • Lossless codecs preserve every bit of the original data. They are used for archiving, professional audio editing, and medical imaging. Examples: FLAC, ALAC, and lossless modes of H.264/H.265 in video.
  • Lossy codecs discard data that the human eye or ear is unlikely to notice, achieving much smaller files. Examples: MP3, AAC, H.264, H.265 (HEVC), and AV1.

Lossy codecs use techniques like transform coding (converting spatial data to frequency data) and motion estimation in video (predicting where blocks move between frames). The amount of compression is controlled by a bitrate setting: higher bitrate means better quality and larger files, lower bitrate means smaller files but more artifacts.

Common Audio Codecs

  • MP3 – the most widely known lossy audio codec. Good compatibility, but older and less efficient than newer options.
  • AAC – the standard for YouTube, iTunes, and most streaming services. Better quality than MP3 at the same bitrate.
  • Opus – a modern lossy codec designed for streaming and voice. Used in Discord, WhatsApp, and many VoIP apps.
  • FLAC – lossless, popular for music archiving and hi-fi listening.

Common Video Codecs

  • H.264 (AVC) – the most widely supported video codec. Works on nearly every device and browser. Used in MP4, MKV, and most streaming.
  • H.265 (HEVC) – the successor to H.264, about 50% better compression, but patent licensing and hardware support vary. Common in 4K video.
  • AV1 – a royalty-free, open codec designed for the web. Used by YouTube, Netflix, and modern browsers. Requires newer hardware for efficient encoding.
  • VP9 – Google’s open codec, used in YouTube and WebM files.

How to Choose a Codec

Choosing a codec depends on your goal:

  1. For maximum compatibility (e.g., sharing a video with someone who might play it on an old TV or phone), use H.264 in an MP4 container with AAC audio.
  2. For archiving or editing (where you need to preserve quality), use a lossless codec like FLAC for audio or a high-bitrate intermediate codec like ProRes or DNxHD for video.
  3. For streaming over the internet (e.g., uploading to YouTube or streaming to a smart TV), use H.264 or AV1 if your device supports it. Check the playback device’s specs.
  4. For voice calls (like Zoom or Discord), Opus is the standard because it handles speech well at low bitrates.

If you are unsure, H.264 + AAC in an MP4 container is the safest default. Most devices and platforms support it.

Common Codec Problems and Fixes

You might encounter a video that plays audio but no video, or a file that won’t open at all. That usually means the codec is missing or not supported by your player. Here’s what to do:

  1. Check the file’s codec using a tool like MediaInfo (free, official). It shows the exact video and audio codecs inside the file.
  2. Use a player that includes many codecs, such as VLC Media Player (free, official). VLC bundles most common codecs and can play almost anything.
  3. If you need to play on a specific device (like a smart TV or game console), convert the file to a compatible format using HandBrake (free, official). Choose H.264 + AAC in MP4 for the widest support.
  4. If a video call has poor quality, it’s usually a bandwidth issue, not a codec problem. Lower the call resolution or check your internet connection.

If you are trying to play a file on a device that doesn’t support the codec, the only real fix is to convert the file or use a different player. There is no way to make a device support a codec it doesn’t have hardware or software for.

Codec vs. Container vs. Format

People often mix up these three terms. A codec is the compression algorithm. A container is the file wrapper that holds the compressed streams, metadata, and subtitles. A format is the combination of container and codecs. For example:

  • MP4 is a container. It can contain H.264, H.265, or AV1 video, and AAC or MP3 audio.
  • MKV is a container that can hold almost any codec, including lossless ones.
  • AVI is an older container, often used with DivX or Xvid codecs.

When you download a video, the file extension tells you the container, not the codec. Two files with the same .mp4 extension might use different codecs, so one plays and the other doesn’t.

Hardware vs. Software Codecs

Codecs can be implemented in software (running on your CPU) or hardware (dedicated chips in your GPU, phone, or TV). Hardware encoding/decoding is faster and uses less battery, but only supports specific codecs. Software encoding is more flexible but slower. When you record video on a phone, it uses the hardware encoder. When you convert a video on your computer with HandBrake, it can use either. For editing, software encoding is often preferred because it offers more control. For streaming, hardware encoding is common to keep latency low.

Frequently Asked Questions

Is a codec the same as a file format?

No. A file format (like MP4) is the container. The codec is the compression algorithm inside. You can have an MP4 file with H.264 video or AV1 video—same container, different codecs.

Why do some videos not play on my TV?

Your TV’s built-in player only supports certain codecs. Most TVs support H.264, but not all support H.265 or AV1. Check your TV’s manual for supported codecs, or convert the video to H.264 in MP4.

What is the best codec for YouTube?

YouTube recommends uploading H.264 video in MP4 with AAC audio. YouTube will re-encode your video to multiple formats for streaming, but uploading H.264 ensures compatibility and good quality.

Do codecs affect video quality?

Yes. Lossy codecs lose quality, but the amount depends on the bitrate and encoder settings. A high-bitrate H.264 video can look better than a low-bitrate AV1 video, even though AV1 is more efficient. Always use a high enough bitrate for your resolution and frame rate.

Can I install a codec to make a video play?

Sometimes. On Windows, you can install a codec pack like K-Lite (official, free) to add support to Windows Media Player. On macOS and mobile devices, you usually can’t install system-wide codecs; you need a player like VLC that includes them.