SIP Trunk Codec: G.711 vs G.729 vs Opus and Which to Use
For a SIP trunk codec, G.711 (ulaw in North America, alaw elsewhere) is the safe first choice, G.729 suits bandwidth-limited links, and Opus only works if the carrier explicitly supports it. Match codec lists on both legs to avoid transcoding.
- A G.711 call uses about 87 kbps per direction on the wire at 20 ms; G.729 uses about 31 kbps.
- Transcoding G.729 or Opus costs far more CPU than G.711 passthrough, so choose codecs that both legs share.
- G.729 patents expired in 2017, but Asterisk still needs a codec module for it; Opus needs a separate binary module in Asterisk.
- Use G.711 first on internet trunks, G.729 as the bandwidth fallback, and Opus only with explicit carrier support.
- Verify with pjsip set logger on, core show channel and core show translation instead of guessing.
Which SIP trunk codec should I use?
The best SIP trunk codec is the one both sides of the call agree on without translation. For nearly every PSTN trunk that is G.711: ulaw in North America and Japan, alaw in Europe and most other regions.
G.729 is the usual answer when the WAN is the bottleneck. Opus is excellent, but carriers almost never accept it on PSTN trunks, so it belongs mainly on WebRTC and on providers that state support.
The rest of this page gives numbers, a decision table, ready-to-paste config and a way to prove no transcoding is happening.
G.711 vs G.729 vs Opus side by side
Payload bitrate is only part of the story. Quality, CPU and licensing change the real cost of each codec.
| Property | G.711 (ulaw/alaw) | G.722 | G.729 | Opus |
|---|---|---|---|---|
| Payload bitrate | 64 kbps | 64 kbps | 8 kbps | 6 to 510 kbps (voice typically 16 to 40) |
| Audio band | Narrowband 300-3400 Hz | Wideband 7 kHz | Narrowband | Wide to fullband |
| Quality (MOS) | About 4.1 to 4.4 | Better than G.711 on HD phones | About 3.9, drops with tandem encoding | Highest, tolerant of packet loss |
| Transcoding CPU | Nearly free (ulaw to alaw cheap) | Moderate | Heavy | Heavy |
| Licensing | None | None | Patents expired 2017; Asterisk module varies | Royalty free; Asterisk needs separate binary or build |
| Fax / modem | Works (T.38 preferred) | No | No | No |
| PSTN carrier support | Universal | Rare | Common | Rare |
How much bandwidth does one call really use?
The codec payload is not the wire rate. Each RTP packet adds 12 bytes of RTP, 8 of UDP and 20 of IPv4, a 40 byte header, plus Layer 2 framing (about 18 bytes on Ethernet). That overhead is paid per packet, so shorter packetization costs more.
At 20 ms there are 50 packets per second. G.711 carries 160 bytes of payload per packet, G.729 only 20 bytes, so the header is a huge share of the G.729 stream.
| Codec / ptime | Payload per packet | IP-level rate (per direction) | Notes |
|---|---|---|---|
| G.711 at 20 ms | 160 B | About 80 kbps (87 kbps with Ethernet framing) | Standard sizing figure: about 87 kbps |
| G.711 at 30 ms | 240 B | About 74.7 kbps | Fewer packets, more delay |
| G.711 at 40 ms | 320 B | About 72 kbps | Delay and loss hurt more |
| G.729 at 20 ms | 20 B | 24 kbps (about 31 kbps with Ethernet framing) | Standard sizing figure: about 31 kbps |
| G.729 at 40 ms | 40 B | 16 kbps | Saves bandwidth, but each lost packet drops 40 ms |
| G.729 with cRTP | 20 B | About 11 to 12 kbps | Needs cRTP on both link ends; rarely used today |
What order should I set codecs in for each scenario?
Order matters because the answering side usually picks the first codec in its own list that also appears in the offer. Put the SIP trunk codec you actually want first, and only list codecs you can support without transcoding.
Common mistakes: enabling every codec, using G.729 for fax or modems, G.729 with music on hold, mixing ulaw and alaw across legs, and forgetting that G.729 expects 20 ms ptime.
| Scenario | Recommended order | Why |
|---|---|---|
| LAN / internal phones | g722, ulaw (or alaw) | HD voice is free on a LAN; G.711 fallback for older phones |
| WebRTC clients | opus, ulaw | Browsers require Opus and G.711 |
| Limited WAN (branch, remote worker) | g729 or low-bitrate opus, then ulaw | Saves roughly 55 kbps per call versus G.711 |
| Internet trunk, ample bandwidth | ulaw/alaw only | Universal carrier support, no transcoding, best fax behaviour |
| Internet trunk, constrained | ulaw/alaw, g729 | G.729 as fallback when the carrier supports it |
| Opus trunk | opus, ulaw | Only if the carrier states Opus support, and keep G.711 as fallback |
How do I configure the codecs in pjsip.conf and FreePBX?
In Asterisk, always use disallow=all first, then allow= in your preferred order. The same rule applies on the trunk endpoint and on every extension. In FreePBX the equivalent is Settings > Asterisk SIP Settings > Codecs for the global list, plus the Codecs checkboxes and ordering on each trunk (PJSIP Settings tab) and extension.
This example uses a G.711 trunk with G.722 and ulaw internally, and keeps DTMF on RFC 4733 (named rfc4733 in current Asterisk; older versions used rfc2833).
; Carrier trunk (North America: ulaw; use alaw in Europe)
[carrier-trunk]
type=endpoint
context=from-trunk
disallow=all
allow=ulaw
allow=g729 ; only if the carrier supports it and you have the module
dtmf_mode=rfc4733
direct_media=no
rtp_symmetric=yes
force_rport=yes
rewrite_contact=yes
media_address=203.0.113.10 ; public IP when behind NAT
; Internal phone
[1001]
type=endpoint
context=from-internal
disallow=all
allow=g722
allow=ulaw
dtmf_mode=rfc4733
direct_media=no
; Remote user over a limited WAN
[2001]
type=endpoint
context=from-internal
disallow=all
allow=g729
allow=ulaw
dtmf_mode=rfc4733
rtp_symmetric=yes
force_rport=yesWhy is G.729 or Opus transcoding a problem, and what does it cost?
A G.711 to G.711 call is mostly packet forwarding, so one core handles thousands of them. Ulaw to alaw is a lookup table, so it is also cheap. G.729 and Opus transcoding run real encoders and decoders, so as an order of magnitude plan for tens to low hundreds of simultaneous transcoded channels per core, depending on CPU and module, rather than thousands. Benchmark on your own hardware before sizing.
Tandem encoding also hurts quality. Each lossy hop (for example G.729 to G.711 to G.729) lowers MOS, which is why a lossy codec should be used end to end rather than patched in the middle.
Licensing: G.729 patents expired in 2017, so the codec itself is royalty free. What varies is the Asterisk binary. Open source Asterisk does not ship a G.729 translator, third-party codec_g729a builds exist with their own terms, and commercial vendors may still sell channel licenses. Opus is royalty free, but the open source Asterisk core does not include Opus transcoding; it needs a separate Digium/Sangoma binary module or a build with Opus support.
How do I check that calls are not being transcoded?
Transcoding appears when the two channels of a bridged call have different formats. Check the SDP, then the channel formats, then the translation table.
- Turn on SIP tracing with pjsip set logger on and place a call. In the INVITE and the 200 OK, read the m=audio line (for example m=audio 10500 RTP/AVP 0 101) and the a=rtpmap lines. Payload 0 is PCMU, 8 is PCMA, 9 is G.722, 18 is G.729 and 101 is telephone-event for DTMF. Opus uses a dynamic payload with a=rtpmap:111 opus/48000/2.
- Run core show channels verbose while the call is up to see each channel.
- Run core show channel PJSIP/carrier-trunk-00000001 and compare ReadFormat, WriteFormat, NativeFormats and the translation path on both legs. If one leg is ulaw and the other g722 or g729, Asterisk is transcoding.
- Run core show translation to see the cost of each pair and whether a G.729 or Opus module is loaded at all.
- If audio problems appear, capture with rtp set debug on or sngrep to confirm RTP in both directions and a stable ptime.
asterisk -rx "pjsip set logger on"
asterisk -rx "core show channels verbose"
asterisk -rx "core show channel PJSIP/carrier-trunk-00000001"
asterisk -rx "core show translation"
asterisk -rx "pjsip show endpoint carrier-trunk"
sngrepCommon questions
Is Opus supported by SIP trunk providers?
Mostly no for PSTN trunks, where G.711 is universal and G.729 is common. Some modern SIP and WebRTC-oriented providers do accept Opus, so ask the carrier to confirm it and the payload settings, and always keep G.711 as a fallback.
What is the best codec for a SIP trunk?
G.711 ulaw (North America, Japan) or alaw (Europe and most other regions) is the best default because carriers accept it, it is cheap to process and it handles fax and DTMF well. Choose G.729 only when bandwidth is the real constraint.
Do I have to pay for G.729 in Asterisk?
The codec patents expired in 2017, so the algorithm is royalty free. Whether you pay depends on the Asterisk module or commercial license you use, since open source Asterisk does not include a G.729 translator.
How do I avoid transcoding in Asterisk?
Use disallow=all and the same allow= codecs on both endpoints, with the common codec first on each. Avoid mixing ulaw and alaw across legs, and confirm with core show channel that read and write formats match.
Which codec is best for limited WAN bandwidth?
G.729 at 20 ms uses about 31 kbps per direction versus about 87 kbps for G.711, so it is the usual choice. Opus at a low bitrate is an alternative if both endpoints support it, but it is not accepted by most carriers.