π΅ 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.
π Table of Contents
π 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:
| Codec | Bitrate | Total Bandwidth (per direction) | Quality (MOS) | CPU Usage | Best For |
|---|---|---|---|---|---|
| G.711 (ulaw/alaw) | 64 kbps | 87.2 kbps | 4.4 (Excellent) | Low | LAN, fiber, high-bandwidth connections |
| G.729 | 8 kbps | 31.2 kbps | 3.9 (Good) | High | Low-bandwidth WAN, remote workers |
| Opus | 6-50 kbps | 20-50 kbps | 4.5 (Excellent) | Medium-High | WebRTC, variable bandwidth, modern apps |
| G.722 (HD Voice) | 64 kbps | 87.2 kbps | 4.5 (HD wideband) | Low | Internal 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.
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:
| Codec | Payload | IP/UDP/RTP Overhead | Total Per Direction | Total Bidirectional | 10 Concurrent Calls |
|---|---|---|---|---|---|
| G.711 | 64 kbps | 23.2 kbps | 87.2 kbps | 174.4 kbps | 1.74 Mbps |
| G.729 | 8 kbps | 23.2 kbps | 31.2 kbps | 62.4 kbps | 624 kbps |
| G.722 | 64 kbps | 23.2 kbps | 87.2 kbps | 174.4 kbps | 1.74 Mbps |
| Opus | 20-40 kbps | ~15 kbps | 35-55 kbps | 70-110 kbps | 700 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
| Issue | Possible Cause | Solution |
|---|---|---|
| No audio on calls | Codec mismatch between endpoints | Ensure both endpoints support at least one common codec (e.g., G.711) |
| Poor audio quality | Using G.729 when G.711 would work | Set G.711 as the preferred codec if bandwidth allows |
| One-way audio | NAT/firewall blocking RTP, or codec mismatch | Check NAT settings, open RTP ports, verify codec negotiation |
| High CPU usage | Transcoding between codecs (e.g., G.711 β G.729) | Use the same codec on both ends to avoid transcoding |
| Bandwidth exhaustion | Using G.711 for all calls on limited bandwidth | Switch to G.729 or Opus for bandwidth-constrained environments |
| HD voice not working | One endpoint doesn't support G.722 | Verify 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
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.
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.
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.
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.
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.
π Related Articles & Resources (NetviaVoice)
Explore more guides to optimize your business communications:
β¨ For personalized assistance with codec configuration, VoIP setup, or call quality optimization, visit our Services page or contact our team directly.
π’ Ready to configure codecs for optimal VoIP performance? Let NetviaVoice help you get it right.