What a codec is
When you speak on the phone, the microphone produces a continuous signal. To send it over a network it has to be sampled, that is measured thousands of times per second, and each measurement turned into numbers. The codec (short for coder-decoder) is the rule that defines how to do this: how many measurements per second, how many bits for each, and whether and how to compress the result.
During a VoIP call the two devices agree on the codec at the start, during SIP negotiation. The caller offers a list of codecs in order of preference in the session description (SDP); the side that answers picks the first one it also knows. If there is no codec in common, the call does not go through. If you want a refresher on how a VoIP call works from the beginning, the guide to VoIP for business is the place to start.
Three factors shape the experience:
- the audio bandwidth, meaning which frequencies of the voice reach the other side: the wider it is, the more natural the voice sounds
- the bitrate, meaning how much data per second is needed
- the complexity, meaning how much processing power the phone or PBX needs to encode and decode
G.711: the baseline codec of telephony
G.711 has been the ITU standard for digital telephony for decades and is the codec every VoIP device supports. It samples the voice 8,000 times per second with 8 bits per sample: the result is a 64 kbit/s stream, carrying the voice between roughly 300 and 3,400 Hz. That is the same quality as traditional landline telephony, known as narrowband.
A-law and µ-law
G.711 comes in two variants, which differ in the curve used to compress the signal values:
- G.711 A-law (often shown as PCMA) is the standard in Europe and most of the world
- G.711 µ-law (PCMU, sometimes written u-law or mu-law) is the standard in North America and Japan
Quality is practically the same. In Europe it makes sense to put A-law before µ-law: it is the variant used by European telephone networks and avoids needless conversions.
Strengths and weaknesses
G.711 compresses almost nothing, so it loses no quality and adds no processing delay. The price is bandwidth: with IP, UDP and RTP packet headers a G.711 call uses about 100 kbit/s in each direction. On fibre or fibre-to-the-cabinet broadband that is very little; on a slow ADSL line, with several calls at once and other traffic, it needs to be taken into account.
G.722: high-definition voice
G.722 is the codec behind so-called HD voice. It samples the voice 16,000 times per second and carries frequencies between roughly 50 and 7,000 Hz: you hear the difference straight away, consonants such as "f" and "s" become distinguishable and the voice sounds like a person in the room rather than "on the phone".
What surprises many people is that G.722 uses the same bandwidth as G.711: 64 kbit/s of audio, about 100 kbit/s per direction with headers. So better quality comes at no extra network cost.
When you really get HD
High definition only happens if both ends of the call use G.722. In practice:
- between two extensions in the same office, both with compatible phones or apps, the call is in HD
- to a landline or a mobile on the traditional network the call almost always runs in narrowband, because the other network works with G.711
This is not a flaw: it is the reason to set G.722 as the first codec with G.711 right after it. When HD is possible it is used; when it is not, the call still goes through.
G.729 and Opus: what to know
You will come across other codecs in the VoIP world too. They are worth knowing, not least because many phones and PBXs offer them by default.
G.729
G.729 compresses heavily: 8 kbit/s of audio, about 30 kbit/s per direction with headers. It was born when bandwidth was expensive and is still used on very slow or satellite links. Quality is narrowband and somewhat below G.711, especially with hold music and tones. For years it required licences; today the main patents have expired, but not every device includes it.
Opus
Opus is a modern, open and very flexible codec: it scales from a few kbit/s up to high bitrates and copes well with packet loss. It is the codec most used for browser calls with WebRTC and in many messaging apps.
What Vohippo accounts use
Vohippo SIP accounts work with G.711 A-law, G.711 µ-law and G.722. G.729 and Opus are not available on the accounts. With today's connections this is not a practical limitation: G.722 gives better quality than G.729, and G.711 works with any device. If your phone offers G.729 or Opus at the top of its list nothing serious happens, but it is worth removing them for a clean negotiation.
Quick comparison
| Codec | Audio bandwidth | Audio bitrate | Bandwidth per direction (approx.) | On Vohippo accounts |
|---|---|---|---|---|
| G.711 A-law (PCMA) | 300-3,400 Hz | 64 kbit/s | 100 kbit/s | Yes |
| G.711 µ-law (PCMU) | 300-3,400 Hz | 64 kbit/s | 100 kbit/s | Yes |
| G.722 | 50-7,000 Hz | 64 kbit/s | 100 kbit/s | Yes |
| G.729 | 300-3,400 Hz | 8 kbit/s | 30 kbit/s | No |
| Opus | variable, up to full band | 6-510 kbit/s | variable | No |
How much bandwidth the office needs
The sum is simple: number of simultaneous calls times 100 kbit/s, for upload and for download. A garage with 3 lines ringing at the reception desk needs about 300 kbit/s per direction at the busiest moment; a call centre with 30 active seats reaches about 3 Mbit/s per direction. You decide the number of simultaneous outbound calls on each account with «Simultaneous outbound calls».
Stability matters more than speed: a fibre line with irregular delays (jitter) or packet loss causes more trouble than a slow but steady connection. If the office often downloads large files, consider giving voice traffic priority on the router (QoS).
How to set codecs on phones and PBXs
The recommended order is the same on any device:
- G.722
- G.711 A-law (PCMA)
- G.711 µ-law (PCMU)
All other codecs should be disabled. For keypad tones (DTMF) use RFC 4733, which on many devices still appears under its old name RFC 2833 or as "telephone-event": the tones travel as separate events and are not distorted by the codec.
IP phones
On desk phones the codecs are usually found in the account settings, in an audio or codec section, with two lists: enabled and disabled. Move the three codecs into the right order and leave the packet duration (ptime) at 20 ms, the standard value. The full steps are in the guide on how to configure a VoIP phone, with versions for Yealink, Grandstream and the other brands.
Softphones and apps
In desktop softphones you choose the codecs in the account's audio settings; some free versions include only G.711, which is perfectly fine. The browser webphone and the Vohippo app for iPhone and Android are ready to use with the account. See the guide on how to set up a softphone.
Asterisk and FreePBX
On Asterisk with PJSIP the codecs are set on the trunk endpoint, in the same order:
[vohippo]
type=endpoint
disallow=all
allow=g722,alaw,ulaw
dtmf_mode=rfc4733
The rest of the configuration is in the guide to configuring the trunk on Asterisk; on FreePBX the same values go into the trunk settings in the web interface, as explained in the guide to the SIP trunk on FreePBX. Remember that the PBX extensions also need G.711 among their allowed codecs: if an extension only speaks a codec the trunk does not have, the PBX has to convert the audio (transcoding), with more load and some loss of quality.
3CX
On 3CX the codec list is in the trunk settings. Keep G.722 and G.711 A-law at the top, then µ-law. The details are in the guide to the SIP trunk on 3CX.
Problems caused by codecs
Many problems that look like network issues are actually codec issues. Here is how to recognise them.
| Symptom | Likely cause | What to do |
|---|---|---|
| The call is rejected immediately with error 488 (Not Acceptable Here) | No codec in common | Enable G.711 A-law and µ-law on the device |
| Total silence in both directions after answering | Codec announced but not actually supported, or a NAT problem | Check the codec list, then the NAT guide |
| Metallic or robotic voice | Transcoding in a PBX or packet loss | Use the same codec on extensions and trunk, check the network |
| Menu tones of a service are not recognised | DTMF sent inside the audio | Set DTMF to RFC 4733 |
| HD voice between extensions not active | G.722 disabled on one of the two devices | Put G.722 first on both |
If the codec is fine and audio only comes through one way, the problem is almost always the network: router, SIP ALG or firewall. We cover it in the guide to NAT, firewalls and ports for VoIP.
A practical example
An accountancy practice with 6 people has desk phones that support G.722 and one colleague who works from home with the app. By setting G.722, A-law and µ-law on every account, calls between colleagues are in HD, including those to the remote colleague, and free calls between short extensions use no credit. Calls to clients, which come from mobiles or the landline network, run in G.711 without anyone touching anything. Bandwidth at peak, with 6 calls at once, stays around 600 kbit/s per direction.
To get started you only need one SIP account per person, which you create after signing up at https://cloud.vohippo.com/register, and the per-second price list to see what outside calls cost.
Frequently asked questions
What is the best codec for VoIP?
For quality, G.722, which carries the voice in high definition with the same bandwidth as G.711. For compatibility, G.711, which works with every device and with the traditional phone network. The right setting is to have both, with G.722 first.
What is the difference between G.711 A-law and µ-law?
They use two different curves to compress the signal values, but quality is practically the same. A-law is the European standard, µ-law the North American and Japanese one: in Europe it is best to put A-law first and keep µ-law as a fallback.
How much bandwidth does a VoIP call use?
With G.711 or G.722 about 100 kbit/s in each direction, headers included. To work out what the office needs, multiply by the maximum number of simultaneous calls and add a margin for other traffic.
Can I use G.729 with Vohippo?
No, Vohippo accounts work with G.711 A-law, G.711 µ-law and G.722. If your device offers G.729, remove it from the list: the call will use G.722 or G.711, which on today's connections give the same or better quality.
Why does the voice sound metallic on some calls?
Usually because of packet loss on the network or a codec conversion inside a PBX. Check that extensions and trunk use the same codecs and, if the problem persists, check the stability of the connection and the Wi-Fi.