Howwise RSS
VoIP & Phone Systems7 min read

SIP Trunk Codec: G.711 vs G.729 vs Opus and Which to Use

Short answer

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.

Key takeaways
  • 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.

PropertyG.711 (ulaw/alaw)G.722G.729Opus
Payload bitrate64 kbps64 kbps8 kbps6 to 510 kbps (voice typically 16 to 40)
Audio bandNarrowband 300-3400 HzWideband 7 kHzNarrowbandWide to fullband
Quality (MOS)About 4.1 to 4.4Better than G.711 on HD phonesAbout 3.9, drops with tandem encodingHighest, tolerant of packet loss
Transcoding CPUNearly free (ulaw to alaw cheap)ModerateHeavyHeavy
LicensingNoneNonePatents expired 2017; Asterisk module variesRoyalty free; Asterisk needs separate binary or build
Fax / modemWorks (T.38 preferred)NoNoNo
PSTN carrier supportUniversalRareCommonRare
Tip: G.722 sounds better on a LAN, but PSTN trunks rarely accept it. Calls from a G.722 phone to the trunk are transcoded to G.711 at the edge, so use it only for internal calls.

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 / ptimePayload per packetIP-level rate (per direction)Notes
G.711 at 20 ms160 BAbout 80 kbps (87 kbps with Ethernet framing)Standard sizing figure: about 87 kbps
G.711 at 30 ms240 BAbout 74.7 kbpsFewer packets, more delay
G.711 at 40 ms320 BAbout 72 kbpsDelay and loss hurt more
G.729 at 20 ms20 B24 kbps (about 31 kbps with Ethernet framing)Standard sizing figure: about 31 kbps
G.729 at 40 ms40 B16 kbpsSaves bandwidth, but each lost packet drops 40 ms
G.729 with cRTP20 BAbout 11 to 12 kbpsNeeds cRTP on both link ends; rarely used today
Warning: Size links per direction and per concurrent call, and add signalling and headroom. Do not run a WAN above about 70 to 75 percent voice load, and reserve it with QoS (DSCP EF, 46) so data bursts cannot starve RTP.

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.

ScenarioRecommended orderWhy
LAN / internal phonesg722, ulaw (or alaw)HD voice is free on a LAN; G.711 fallback for older phones
WebRTC clientsopus, ulawBrowsers require Opus and G.711
Limited WAN (branch, remote worker)g729 or low-bitrate opus, then ulawSaves roughly 55 kbps per call versus G.711
Internet trunk, ample bandwidthulaw/alaw onlyUniversal carrier support, no transcoding, best fax behaviour
Internet trunk, constrainedulaw/alaw, g729G.729 as fallback when the carrier supports it
Opus trunkopus, ulawOnly 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=yes
Tip: direct_media=yes only helps when two phones on the same network can send RTP straight to each other. On trunks and across NAT keep it off, because the PBX must stay in the media path.

Why 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.

  1. 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.
  2. Run core show channels verbose while the call is up to see each channel.
  3. 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.
  4. Run core show translation to see the cost of each pair and whether a G.729 or Opus module is loaded at all.
  5. 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"
sngrep
Warning: SIP tracing writes full headers to the log, which can include credentials and caller data. Turn it off with pjsip set logger off when finished.

Common 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.

Related topics:sip trunkcodecsasteriskg711voip bandwidth