An audio codec (coder/decoder) is the algorithm that compresses and decompresses sound. It decides how audio is stored or streamed, how large the file is for a given quality, and which devices can play it back. Picking the right codec is a balance of fidelity, bitrate, latency, and compatibility.

An abstract waveform around the text “What is an audio codec?”

Codec vs container

A codec is not the same thing as a container. A container (like MP4, MKV, or WebM) is the wrapper that can hold one or more audio and video streams, plus metadata. The codec is the actual compression method used inside that container. For example, an MP4 file often contains AAC audio, while a WebM file typically contains Opus or Vorbis audio.

How audio codecs work

Raw digital audio is usually stored as PCM (pulse‑code modulation). PCM is accurate but large. A codec reduces size by applying compression. Lossless codecs compress PCM without removing information. Lossy codecs go further by discarding details that are less audible to human hearing (psychoacoustic modeling), which yields much smaller files at the cost of some quality.

Lossy, lossless, and uncompressed

  • Lossy: removes data to shrink files. Best for streaming and general listening when size matters. Examples: MP3, AAC, Opus.
  • Lossless: preserves all information while still compressing. Best for mastering, archival, and professional workflows. Examples: FLAC, ALAC.
  • Uncompressed: stores raw PCM. Best for editing pipelines that need zero compression overhead. Examples: WAV, AIFF.

Key settings that affect quality and size

  • Bitrate: the most direct lever for size and quality. Higher bitrate usually means better quality. Variable bitrate (VBR) adapts to complexity; constant bitrate (CBR) is predictable.
  • Sample rate: how many samples per second (e.g., 44.1 kHz, 48 kHz). Higher rates capture more detail but increase size.
  • Channels: mono, stereo, or multichannel. More channels increase size.
  • Bit depth: mainly relevant for lossless/uncompressed audio (e.g., 16‑bit vs 24‑bit).

Common audio codecs and when to use them

  • AAC: a strong default for music and general playback; excellent compatibility in MP4.
  • MP3: legacy, still widely supported, but less efficient than AAC or Opus at the same bitrate.
  • Opus: great for voice, real‑time, and low‑bitrate streaming; excellent quality at small sizes.
  • FLAC: lossless compression for archiving and distribution of high‑quality audio.
  • WAV/AIFF: uncompressed PCM for editing pipelines and interchange.

How to choose the right codec

  • Streaming or podcasts: AAC or Opus, depending on device support requirements.
  • Voice or real‑time: Opus for low latency and efficiency.
  • Archival or mastering: FLAC or WAV.
  • Maximum compatibility: MP3 still wins on legacy devices, but AAC is broadly supported too.

Encode audio with Transloadit

Our 🤖 /audio/encode Robot lets you convert audio to popular codecs with a few parameters. Here’s a minimal example that converts an upload to MP3 at 128 kbps:

{
  "steps": {
    "encode_mp3": {
      "robot": "/audio/encode",
      "use": ":original",
      "preset": "mp3",
      "bitrate": 128000
    },
    "store": {
      "robot": "/s3/store",
      "use": "encode_mp3"
    }
  }
}

Need lossless output or different sample rates? Just switch the preset or set sample_rate and bitrate accordingly.

Next steps