How to Configure Codecs for Optimal VoIP Performance | NetviaVoice

🎡 How to Configure Codecs for Optimal Performance

Summary: Codecs are the engines of VoIP audioβ€”they compress and decompress voice for transmission over IP networks. Choosing and configuring the right codec directly impacts call quality, bandwidth consumption, and system compatibility. This comprehensive guide compares G.711, G.729, Opus, and G.722; explains bandwidth requirements; provides step-by-step configuration for FreePBX, 3CX, and Asterisk; and offers troubleshooting tips for common codec issues.

πŸ” What is a Codec?

A codec (coder-decoder) is an algorithm that compresses and decompresses audio for transmission over IP networks. In VoIP, codecs determine how your voice is digitized, compressed into packets, transmitted across the network, and reconstructed at the other end.

πŸ”Ή How Codecs Work

  • Encoding: Analog voice is converted to digital samples
  • Compression: Samples are compressed to reduce bandwidth
  • Packetization: Compressed audio is placed into RTP packets
  • Transmission: Packets travel over the IP network
  • Decoding: Far-end codec decompresses and plays audio

⚠️ Why Codec Choice Matters

  • Call Quality: Different codecs offer different audio fidelity
  • Bandwidth: Codec choice affects how much bandwidth each call uses
  • Compatibility: Both endpoints must support the same codec
  • CPU Usage: More complex codecs require more processing power

Codec choice can reduce bandwidth per call by up to 65% while maintaining acceptable quality

πŸ“Š Codec Comparison: G.711, G.729, Opus, G.722

Four codecs dominate business VoIP. Here's how they compare:

CodecBitrateTotal Bandwidth (per direction)Quality (MOS)CPU UsageBest For
G.711 (ulaw/alaw)64 kbps87.2 kbps4.4 (Excellent)LowLAN, fiber, high-bandwidth connections
G.7298 kbps31.2 kbps3.9 (Good)HighLow-bandwidth WAN, remote workers
Opus6-50 kbps20-50 kbps4.5 (Excellent)Medium-HighWebRTC, variable bandwidth, modern apps
G.722 (HD Voice)64 kbps87.2 kbps4.5 (HD wideband)LowInternal calls, HD voice conferences

πŸ’‘ Key Insight: G.711 is the industry standard for toll-quality voice. G.729 saves bandwidth at the cost of some fidelity. Opus is the modern choice for adaptive quality. G.722 delivers HD voice but requires both endpoints to support it.

πŸš€ Need Help Configuring Codecs for Your VoIP System? NetviaVoice Can Help

Our VoIP specialists can help you select the right codecs, optimize bandwidth, and configure your PBX for crystal-clear call quality.

πŸ’¬ WhatsApp US
πŸ“ž +92 333 5908806 (Global)
🌐 Our Services
Visit NetviaVoice

πŸ“ˆ Bandwidth Requirements

Understanding bandwidth per call helps you plan network capacity. Here's the breakdown for each codec at the standard 20ms packetization interval:

CodecPayloadIP/UDP/RTP OverheadTotal Per DirectionTotal Bidirectional10 Concurrent Calls
G.71164 kbps23.2 kbps87.2 kbps174.4 kbps1.74 Mbps
G.7298 kbps23.2 kbps31.2 kbps62.4 kbps624 kbps
G.72264 kbps23.2 kbps87.2 kbps174.4 kbps1.74 Mbps
Opus20-40 kbps~15 kbps35-55 kbps70-110 kbps700 kbps - 1.1 Mbps

⚠️ Important: Always add 20-30% headroom for network overhead, VPN encapsulation, and burst traffic. For 10 concurrent G.711 calls, plan for at least 2 Mbps of dedicated voice bandwidth.

πŸ”„ Codec Negotiation & Order

Codec negotiation is the process where two endpoints agree on which codec to use for a call. Each endpoint sends a list of supported codecs in priority order; the first mutually supported codec is chosen.

πŸ”Ή How Negotiation Works

  • Step 1: Caller sends an INVITE with a prioritized list of codecs (e.g., G.711, G.729, Opus)
  • Step 2: Callee compares the list to its own supported codecs
  • Step 3: Callee selects the first codec from the caller's list that it also supports
  • Step 4: Callee responds with the chosen codec, and the call proceeds

Example: If the caller's list is "G.722, G.711, G.729" and the callee only supports G.711 and G.729, the callee will choose G.711 (the first match).

πŸ’‘ Pro Tip: Place your preferred codec first in the list. If you want G.711 for all calls, list it first. If you want to conserve bandwidth, list G.729 or Opus first.

πŸ› οΈ Step-by-Step Codec Configuration

Codec configuration varies by PBX. Here's how to configure the most common systems:

πŸ“€ FreePBX (PJSIP) Configuration

  • 1 Log in to FreePBX Admin and go to Connectivity β†’ Trunks
  • 2 Edit your SIP trunk and go to the pjsip Settings tab
  • 3 Scroll to the Codecs section
  • 4 Select ulaw and alaw (G.711) for toll quality
  • 5 Optionally add g729 if bandwidth is limited
  • 6 Click Submit and Apply Config

πŸ“€ 3CX Configuration

  • 1 In 3CX Management Console, go to Voice & Chat β†’ SIP Trunks
  • 2 Edit your trunk and go to the Options tab
  • 3 Locate the Codecs section
  • 4 Drag codecs to set priority order (first = highest priority)
  • 5 Click OK to save

πŸ“€ Asterisk (sip.conf / pjsip.conf)

In Asterisk, codecs are configured using allow/disallow directives:

Example PJSIP endpoint codec configuration:

disallow = all
allow = ulaw
allow = alaw
allow = g722

The first allow line after disallow = all is the highest priority codec.

πŸ“€ IP Phone Codec Configuration

  • 1 Access the phone's web interface (usually via its IP address)
  • 2 Navigate to Audio Settings or Codec Settings
  • 3 Arrange codecs in priority order (top = highest)
  • 4 Ensure G.711 (ulaw/alaw) is enabled for compatibility
  • 5 Save and reboot the phone if required

βš–οΈ Balancing Quality & Bandwidth

Choosing the right codec requires balancing audio quality against available bandwidth. Here's a decision framework:

βœ… Choose G.711 When:

  • Bandwidth is plentiful (LAN, fiber, high-speed broadband)
  • Call quality is the top priority
  • You have financial, healthcare, or customer-facing calls
  • You don't need to conserve bandwidth

βœ… Choose G.729 When:

  • Bandwidth is limited (DSL, remote sites, overloaded WAN)
  • You need to support many concurrent calls on limited capacity
  • You have remote workers on slow connections
  • Slight quality reduction is acceptable

βœ… Choose Opus When:

  • Using WebRTC or modern softphones
  • You need adaptive quality based on network conditions
  • You want the best quality-to-bandwidth ratio
  • Both endpoints support it

βœ… Choose G.722 When:

  • Both endpoints support HD voice
  • You want superior audio for internal calls
  • Your network has sufficient bandwidth
  • You're using modern IP phones

πŸ”§ Troubleshooting Codec Issues

IssuePossible CauseSolution
No audio on callsCodec mismatch between endpointsEnsure both endpoints support at least one common codec (e.g., G.711)
Poor audio qualityUsing G.729 when G.711 would workSet G.711 as the preferred codec if bandwidth allows
One-way audioNAT/firewall blocking RTP, or codec mismatchCheck NAT settings, open RTP ports, verify codec negotiation
High CPU usageTranscoding between codecs (e.g., G.711 ↔ G.729)Use the same codec on both ends to avoid transcoding
Bandwidth exhaustionUsing G.711 for all calls on limited bandwidthSwitch to G.729 or Opus for bandwidth-constrained environments
HD voice not workingOne endpoint doesn't support G.722Verify both endpoints support G.722; fall back to G.711 if not

πŸ’‘ Pro Tip: Check SIP INVITE messages in your PBX logs or with Wireshark to see exactly which codecs are being offered and negotiated.

πŸ† Codec Configuration Best Practices

βœ… General

  • Use G.711 as the primary codec for best quality
  • Add G.729 as fallback for bandwidth-limited scenarios
  • Enable Opus for WebRTC endpoints
  • Keep G.722 for internal HD calls

βœ… Network

  • Calculate bandwidth per call before deploying
  • Add 20-30% headroom for overhead
  • Implement QoS to prioritize voice traffic
  • Use wired Ethernet for IP phones

βœ… Configuration

  • Match codec settings on both ends
  • Place preferred codec first in the list
  • Avoid transcoding (use same codec on both ends)
  • Document codec strategy for troubleshooting

βœ… Monitoring

  • Monitor MOS scores for quality issues
  • Track bandwidth usage per codec
  • Test call quality after changes
  • Review codec settings quarterly

❓ Frequently Asked Questions

1. What is a codec and why does it matter in VoIP?

A codec (coder-decoder) compresses and decompresses audio for transmission over IP networks. The codec you choose determines call quality, bandwidth consumption, and compatibility with other systems. Choosing the right codec is essential for balancing voice quality with network capacity.

2. Which codec is best for VoIP: G.711 or G.729?

G.711 is best when bandwidth is plentifulβ€”it delivers excellent toll-quality audio at 87.2 kbps per call. G.729 is best when bandwidth is limitedβ€”it uses only 31.2 kbps but offers slightly lower audio fidelity. For most businesses with reliable broadband, G.711 is recommended.

3. How much bandwidth does each codec require?

G.711 requires 87.2 kbps per direction (64 kbps payload + overhead). G.729 requires 31.2 kbps. G.722 (HD voice) requires 87.2 kbps. Opus varies from 20-50 kbps depending on mode. Always calculate both upload and download bandwidth for concurrent calls.

4. How do I change codec settings on my PBX or phone?

In FreePBX, go to Connectivity > Trunks, edit your trunk, and configure codecs in the pjsip Settings tab. In 3CX, go to Voice & Chat > SIP Trunks > Options and adjust codec priority. On IP phones, access the web interface and go to Audio/Codec settings to set codec order.

5. What is codec negotiation and why does order matter?

Codec negotiation is the process where two endpoints agree on which codec to use for a call. Each endpoint sends a list of supported codecs in priority order; the first mutually supported codec is chosen. If your top codec isn't supported by the other side, the next one in the list is usedβ€”so order determines quality and bandwidth outcomes.

πŸ“’ Ready to configure codecs for optimal VoIP performance? Let NetviaVoice help you get it right.

Β© 2025 NetviaVoice β€” Codec Configuration Experts, VoIP Solutions & Business Communications.

NetviaVoice provides codec optimization, VoIP setup, and call quality solutions for businesses of all sizes.