Codecs determine how voice audio is compressed for transmission — directly affecting both call quality and bandwidth consumption. This guide explains the common options and how to choose correctly.
What a Codec Does
A codec compresses audio for efficient network transmission, then decompresses it on the receiving end — different codecs trade off audio quality, bandwidth usage, and CPU processing load differently.
Common VoIP Codecs Compared
| Codec | Bandwidth per Call | Quality | Notes |
|---|---|---|---|
| G.711 (ulaw/alaw) | ~64-87 kbps | Excellent (uncompressed) | Widely compatible, higher bandwidth usage |
| G.729 | ~8-31 kbps | Good | Much lower bandwidth, may require licensing depending on implementation |
| Opus | Variable, ~6-510 kbps | Excellent, adaptive | Modern, flexible, increasingly common default |
| GSM | ~13 kbps | Fair | Older, lower quality, rarely the best choice today |
Choosing a Codec: The Trade-Off
G.711 offers the best raw quality but uses the most bandwidth; G.729 and similar compressed codecs reduce bandwidth significantly at some quality cost — Opus offers a strong modern middle ground with adaptive quality based on available bandwidth.
Calculating Bandwidth for Multiple Concurrent Calls
Total bandwidth = (bandwidth per call) × (number of concurrent calls)
Example: 10 concurrent G.711 calls at ~87 kbps each ≈ 870 kbps total, plus overhead — verify your VPS's actual available bandwidth comfortably exceeds your expected peak concurrent call volume.
Configuring Codec Preference in Asterisk
[1001]
type=endpoint
disallow=all
allow=opus
allow=ulaw
allow=g729
Lists codecs in priority order — Asterisk negotiates the best mutually-supported codec between the two endpoints of a call.
Why Codec Mismatch Causes Problems
If two endpoints (or a trunk and your PBX) don't share a common codec, calls may fail to connect entirely, or Asterisk must transcode between codecs — adding CPU overhead and potential quality degradation compared to a native codec match.
Transcoding Overhead
Converting between codecs in real time is CPU-intensive — minimizing the need for transcoding (by ensuring compatible codec support across your trunk, PBX, and endpoints) improves both call quality and server capacity for concurrent calls.
Bandwidth Overhead Beyond Raw Codec Rate
Actual network bandwidth per call is somewhat higher than the raw codec bitrate due to RTP/UDP/IP packet overhead — budget roughly 10-20% additional headroom beyond the codec's nominal rate for realistic planning.
Choosing Based on Your Actual Constraints
- Limited bandwidth, many concurrent calls — favor compressed codecs (G.729, or Opus at a lower bitrate setting)
- Ample bandwidth, quality is the priority — G.711 or high-bitrate Opus
- Uncertain/variable network conditions — Opus's adaptive bitrate handles this gracefully
Common Errors
Calls connect but with poor audio quality — check for codec mismatch causing transcoding, or genuinely insufficient bandwidth for the negotiated codec under current network conditions.
Continue Reading
- How to Troubleshoot Common VoIP Quality Issues (Jitter, Latency, Packet Loss)
- VPS Requirements for VoIP and Communication Servers
- How to Set Up SIP Trunking for Your PBX
Browse more articles in VoIP & Communication Servers.