Voice codecs: definition and a practical example
Short answer: Voice codecs are the algorithms that encode speech into digital data for transmission on a call and decode it at the destination, such as G.711, G.729 and Opus.
In Portuguese: Codecs de voz
What are voice codecs?
A voice codec is the algorithm that turns the sound of a voice into bits to travel across the network and rebuilds the sound on the other side. Every VoIP call uses a codec, and both ends need to use the same one. The choice determines how much bandwidth the call consumes, the audio quality and how well it holds up against packet loss.
The three codecs most often found in telephony are:
- G.711 (ITU-T): uncompressed, samples speech at 8 kHz and produces 64 kbit/s. It has two variants, μ-law and A-law; Brazil uses A-law (PCMA). It is the de facto standard on SIP trunks.
- G.729 (ITU-T): compresses to 8 kbit/s. It saves bandwidth but loses quality and distorts DTMF tones sent inside the audio.
- Opus (RFC 6716): an open, adaptive codec from 6 to 510 kbit/s, with audio bandwidth up to 48 kHz. Common in WebRTC and apps.
The codec is agreed at the start of the call through SDP, inside the SIP message. The caller offers a list of codecs; the called party picks one from the list. If none works, the call fails.
In practice
Bandwidth per direction at the IP layer, with 20 ms packets (40 bytes of IP, UDP and RTP header per packet, not counting Ethernet):
| Codec | Audio | Payload per packet | IP bandwidth per direction |
|---|---|---|---|
| G.711 | 64 kbit/s | 160 bytes | 80 kbit/s |
| G.729 | 8 kbit/s | 20 bytes | 24 kbit/s |
| Opus | 6 to 510 kbit/s | variable | variable |
A link carrying 10 simultaneous G.711 calls needs about 800 kbit/s in each direction just for voice. With G.729, about 240 kbit/s. Note that with G.729 the header weighs twice as much as the audio.
How Monitor uses this
When the destination accepts none of the codecs offered on the test call, the call ends with SIP 488 and Monitor counts the circuit as down. See SIP trunk monitoring.
Frequently asked questions
Which codec should I use for VoIP: G.711 or G.729?
G.711 does not compress speech and delivers classic telephone quality, at the cost of 64 kbit/s of audio in each direction. G.729 uses 8 kbit/s but loses quality and interferes with DTMF sent inside the audio. With bandwidth to spare, G.711 is the simpler choice. With tight bandwidth, G.729 fits better. What matters is that both ends accept the same one.
What happens when the two ends have no codec in common?
The SDP negotiation fails and the call does not complete. The destination usually answers with SIP 488 Not Acceptable Here. An SBC in the path can solve it by transcoding, but every transcoding step costs processing and a little quality. For a permanent fix, align the PBX's codec list with the carrier's.