Tip: type a SIP code like 488, or a problem like one-way audio. Use ↑ ↓ and Enter.

Planning

VoIP Codecs Compared: G.711 vs G.729 vs G.722 vs Opus

On this page
  1. Narrowband and wideband
  2. The main codecs
  3. Comparison table
  4. Quality, bandwidth and CPU
  5. Fax, modems and DTMF
  6. What SIP trunks support
  7. How codec negotiation works in SDP
  8. Which codec should you use?

Use G.711 (A-law in South Africa and Europe) for SIP trunks and wherever bandwidth is plentiful, G.722 or Opus for HD voice on internal calls, Opus for WebRTC and lossy networks, and G.729 only when bandwidth is tight and you don't need fax or modems. The best choice is usually the one that avoids transcoding between your phones, PBX and carrier.

Narrowband and wideband

A codec's sampling rate sets the highest frequency it can carry: half the sampling rate. Narrowband codecs sample at 8 kHz and pass roughly 300–3400 Hz, the traditional telephone band. Wideband codecs sample at 16 kHz and pass roughly 50–7000 Hz.

The extra top end carries consonants such as s, f and th, which are hard to tell apart on a narrowband call; the extra bottom end makes voices sound fuller. That is why wideband "HD voice" is easier to understand, especially for names, spelling and unfamiliar accents. Super-wideband (32 kHz sampling) and fullband (48 kHz) go further still, and Opus covers all of these.

The main codecs

G.711 (PCMA and PCMU)

Uncompressed 64 kbps PCM: 8,000 samples per second at 8 bits each, with logarithmic companding. There are two variants. A-law (PCMA, RTP payload type 8) is used in Europe, South Africa and most of the world; µ-law (PCMU, payload type 0) is used in North America and Japan. Converting between them is cheap and almost lossless. G.711 gives the best narrowband quality, costs negligible CPU, is supported everywhere, and is the only common codec that can carry fax and modem tones at all. Its cost is bandwidth: 87.2 kbps per direction on Ethernet.

G.729 and G.729A

CS-ACELP at 8 kbps, with 10 ms frames of 10 bytes and 15 ms of algorithmic delay; RTP payload type 18. G.729A is a reduced-complexity version with the same bitstream, so the two interoperate. Annex B adds voice activity detection and comfort noise and is signalled in SDP with annexb=yes or annexb=no; if the parameter is absent, Annex B is assumed to be on.

Quality is a step below G.711. The ITU-T E-model gives G.729A an equipment impairment factor of 11, against 0 for G.711, and quality drops further each time a call is transcoded through it. G.729's patents have expired, so it is now royalty-free and open-source implementations such as bcg729 exist, although older PBX installations may still carry per-channel licences from the patent era.

G.722

The most common HD voice codec on desk phones: 16 kHz sampling, sub-band ADPCM at 64 kbps (48 and 56 kbps modes exist but are rarely used for VoIP), RTP payload type 9. It uses the same bandwidth as G.711 and little more CPU, so on a LAN it is a free upgrade.

One quirk catches people out. SDP advertises it as G722/8000 even though it samples at 16 kHz. The original RTP profile got the clock rate wrong, and RFC 3551 kept the error for backward compatibility, so G.722 RTP timestamps advance by 8,000 per second. An implementation that "corrects" this to 16000 will not interoperate cleanly.

Opus

Opus (RFC 6716) combines SILK-based speech coding with CELT-based music coding. It runs from 6 to 510 kbps, from narrowband to fullband, with frame sizes from 2.5 to 60 ms, and can change bitrate and audio bandwidth during a call. Built-in concealment, optional in-band forward error correction (useinbandfec=1) and discontinuous transmission make it the most robust choice on lossy networks.

Opus is mandatory to implement in WebRTC, so every browser softphone supports it. In SDP it always appears as opus/48000/2 with a dynamic payload type, whatever bandwidth is actually used (RFC 7587). Support on desk phones and SIP trunks is growing but far less universal than G.711, and it costs more CPU than the older codecs, which matters on a PBX transcoding hundreds of calls.

iLBC and GSM

iLBC (RFC 3951) runs at 13.33 kbps with 30 ms frames or 15.2 kbps with 20 ms frames. Each frame is encoded independently, so it degrades gracefully under loss, which made it popular before Opus. GSM 06.10 full rate (payload type 3, 33-byte frames) still turns up on legacy systems and low-end gateways. Neither is a good choice for a new deployment.

Comparison table

"On the wire" is one direction at 20 ms packetisation (30 ms for iLBC), IPv4 over Ethernet, including RTP, UDP, IP and Ethernet headers. A call uses the same again in the other direction.

CodecSampling / bandCodec bitrateOn the wireCPUBest for
G.711 A-law / µ-law8 kHz, narrowband64 kbps87.2 kbpsVery lowSIP trunks, fax pass-through, universal fallback
G.72216 kHz, wideband64 kbps87.2 kbpsLowHD voice between desk phones
G.729 / G.729A8 kHz, narrowband8 kbps31.2 kbpsModerateThin links with many calls
Opus (at 32 kbps)8–48 kHz, narrow to fullband6–510 kbps55.2 kbpsModerate to highWebRTC, softphones, lossy networks
iLBC (30 ms)8 kHz, narrowband13.33 kbps28.8 kbpsModerateLegacy loss-tolerant links
GSM-FR8 kHz, narrowband13.2 kbps36.4 kbpsLowLegacy only

The VoIP bandwidth guide shows how these figures are calculated, and the bandwidth calculator handles VLAN tags, PPPoE, SRTP and VPN overhead.

Quality, bandwidth and CPU

  • Headers shrink the saving. G.729 is eight times smaller than G.711 at the codec, but only about 2.8 times smaller on the wire, because 58 bytes of headers ride on every 20-byte payload.
  • Bandwidth is rarely the constraint it was. Twenty G.711 calls need about 1.75 Mbps each way. On fibre that is small; on a congested LTE or rural wireless link it is not.
  • Transcoding costs twice. Every conversion uses CPU and adds a little delay, and each pass through a compressed codec loses quality. A call that goes Opus to G.729 to G.711 sounds worse than any one of those alone. Aim for one codec end to end, so the PBX can pass media through untouched.
  • Wideband only helps if it survives the whole path. Calls that leave through a PSTN interconnect are normally narrowband, so HD voice mostly benefits internal and on-net calls.
  • Loss matters more than codec. A G.711 call with 3% loss sounds worse than a clean G.729 call. See what MOS measures for how codec and network impairments combine.

Fax, modems and DTMF

Compressed speech codecs model the human voice. Fax, modem, alarm panel and card-machine tones are not voice, and G.729 or Opus destroy them. There are two fixes:

  • T.38 fax relay. The gateway demodulates the fax and sends the image data as packets (m=image ... udptl t38 in SDP), usually switching via a re-INVITE after the call starts as audio. Both ends and the carrier must support it.
  • G.711 pass-through. Force G.711 for those devices, with silence suppression off and, where the gateway allows it, a fixed jitter buffer. It works on clean networks, but packet loss quickly breaks faxes.

DTMF has the same problem: tones sent in-band through G.729 are distorted, and IVRs miss or double digits. Send DTMF out of band as RFC 4733 telephone-events (which replaced RFC 2833), shown in SDP as telephone-event/8000, often on payload type 101. Make sure both sides agree on the method; SIP INFO is an alternative some systems use.

What SIP trunks support

Almost every SIP trunk accepts G.711, and in South Africa the PSTN uses A-law, so put PCMA first on trunks there. Many carriers also accept G.729, sometimes only once it is enabled on your account. G.722 and Opus support on trunks varies widely, so check the provider's interop guide rather than assuming. Also check the packetisation they expect; 20 ms is the safe default.

How codec negotiation works in SDP

SIP uses the SDP offer/answer model (RFC 3264). The INVITE offers payload types on the m= line in order of preference:

m=audio 40000 RTP/AVP 8 0 9 18 101
a=rtpmap:8 PCMA/8000
a=rtpmap:0 PCMU/8000
a=rtpmap:9 G722/8000
a=rtpmap:18 G729/8000
a=fmtp:18 annexb=no
a=rtpmap:101 telephone-event/8000
a=fmtp:101 0-16
a=ptime:20

The answerer keeps the codecs it supports from that list and returns them in its 183 or 200 OK. An answer of m=audio 30000 RTP/AVP 8 101 means G.711 A-law with RFC 4733 DTMF. RFC 3264 recommends that the answer keeps the offer's order unless there is a reason not to, but PBXs let you choose whose preference wins, for example FreeSWITCH's inbound-codec-negotiation profile setting or the incoming_call_offer_pref endpoint option in Asterisk's PJSIP.

If there is no codec in common, the call fails with 488 Not Acceptable Here. Other SDP mismatches, such as SRTP required on one side only, produce the same response. When you see a 488, compare the m= lines in the INVITE with the codecs allowed on the receiving endpoint or trunk.

Which codec should you use?

  1. SIP trunk to the PSTN in South Africa or Europe: G.711 A-law first, µ-law second, G.729 only if the link demands it.
  2. Internal calls between desk phones on a LAN: G.722 first, G.711 as fallback.
  3. WebRTC and softphones on home broadband or mobile data: Opus with FEC enabled.
  4. Many calls on a thin link: G.729 or low-bitrate Opus, after checking fax, DTMF and carrier support. Fix QoS before you trade away quality.
  5. Fax machines, alarm panels and card machines: T.38 or G.711 only, never a compressed codec.
  6. Everything: list the same codecs in the same order on phones, PBX and trunk, so calls never need transcoding.

Try the VoIP Bandwidth Calculator

Bandwidth per call and for your whole office, for G.711, G.729, Opus and more, including all overhead.

Keep reading