How VoIP works: protocols, codecs and more
Translation of the original in Catalan. Read it in: CatalàCastellano
Here you have the continuation I promised you of the basics of VoIP. I will try to make this article as understandable as the previous one but it will not be simple because the topics to be covered are already quite technical and specialised. Even so it is very necessary to be clear about them, otherwise when we deal with real VoIP systems we will not know what the manuals or the other colleagues are referring to when they explain the reasons why things happen. Or simply, why certain devices are needed in the configurations.
Once again I have to refer to Network System Design Line, this time to the article How VoIP works: Protocols, codecs, and more (local).
Summing up the basic ideas
In the article about the basics of VoIP the process a VoIP call follows was very clear. The importance of the time it takes to sample the analogue waves of the voice (digitising the voice) and the space that this digitisation occupies was also hinted at. That will have a direct effect on the time we take to transport that information to the other end, where the reverse process will be done until the interlocutor hears our voice.
Well then, in this document I will focus on explaining what is done after digitising the voice, that is, that information is compressed before being transported so that it takes less space (that is what the codecs do). On the other hand, we have to think that when we send an email or a photograph through an IP network that information is not time sensitive. That is, it does not matter to us if it takes a few seconds more or less to arrive, that does not affect the message being transported. Obviously in a conversation that is not the case and those packets have to arrive fast enough at the other end for the feeling of "real time" to be enough.
IP networks, by default, are best-effort networks, that means that all the packets that travel through them try to get through as fast as possible but without any kind of arbitration. To put it plainly, the law of the strongest. Therefore, it is initially an environment not very suitable for transporting time sensitive information. For example, real time information (or streaming) of audio and/or video.
In order to adapt that medium better to time sensitive communications, QoS techniques are used. That is, we try to set up an arbitration system in the nodes of the network in order to prioritise time sensitive traffic. For example, VoIP traffic. If the network we have to work on does not carry much traffic load that is not too important. We must bear in mind that the internet is not a network with QoS. Therefore, it is a hostile environment for our VoIP calls.
Going a bit into technical topics, what we have to achieve as far as the delays of the network between the two ends are concerned are times below 100ms. Although with per-packet delays of 100 to 200ms calls can still get through, annoying phenomena for the interlocutors can already start to appear. Often echo problems.
Typical problems of an IP network
Which are the problems we have to try to avoid an IP network having in order to carry VoIP over it:
- Delay the delay, the time the packets take to travel from the starting point to the end. Delays that are too high usually cause acoustic echo problems.
- Packet loss loss of packets, especially in WAN networks; if the packets have to travel through many points (gateways) they could be lost. Losing therefore information of the message being transported.
- Jitter sudden and unwanted changes in the time the packets take to arrive, this can cause disorder. To solve it, buffers and small packets, with little information, are often used.
- Echo the packets arrive more than once through different paths. It is not the same as acoustic echo.
Summary of the steps the voice follows until it reaches the other end
In the following diagram we can see all the steps, one by one, that our voice follows until it reaches the interlocutor. As we can see each of the steps has a series of codecs, protocols and associated standards which are described next.

As has already been said, the first thing done after sampling the voice (digitising) is to encode and compress it in order to reduce the bandwidth requirements. That process is carried out by the codecs.
The compressed data packets move through the networks thanks to a transport protocol. The gateways are in charge of routing those packets between different IP networks (or other kinds, if needed) until the packets reach their destination. When it arrives at the destination the received packets are decoded (and decompressed) and converted back into audio.
VoIP in the OSI model
The 7 layer OSI model defines any networking process (digital interconnection in a network). If there are two ends that want to have a communication session, the data they generate starts at layer 7, undergoing the necessary encapsulations until it reaches the transmission medium (through which the data travels: cable, air, light, etc.); at the other end the reverse process takes place from the medium up to the user. Well then, that is what the following diagram shows us and it places each of the protocols in one of the layers.

Session control: H.323 vs. SIP
The first thing we need to establish a VoIP communication is a session protocol that tells us how we inform the network that we exist, how we try to communicate with other users or how we receive communications from other users. The two best known protocols in charge of that are H.323 and SIP. Although there are many others such as IAX (protocol used by Asterisk).
International Telecommunication Union (ITU) H.323
H.323 is an ITU standard originally developed to send voice and data in real time (videoconferencing and similar). Although one of the first applications it had was VoIP. In fact, H.323 is more than a protocol, it is in itself a group of standards, codecs and protocols that say how to establish a multimedia communication through an IP network. For example, the signalling protocol H.323 uses is H.225 and the feature negotiation protocol is H.245.
Session Initiation Protocol (SIP)
SIP was defined by the IETF in RFC 3261. It was developed especially for IP telephony. In fact, it is considered a much cleaner and simpler solution than H.323. SIP is used with SDP in order to discover users; it also offers the ability to discover features and to manage calls. SDP is essentially a format that describes how to set the initialisation parameters in order to exchange the multimedia information. Basically SIP/SDP is analogous to H.225/H.245 in the H.323 protocol.
The SIP protocol also allows us to establish connections between two ends without the need to have a server. Although that is not the usual thing. Since normally what SIP clients do is register against a public server in order to show themselves to the rest of the clients of the network.
Transport layer protocols
The signalling protocols described above are responsible for establishing the configurations to be used in a multimedia session between two users. But that signalling information will travel through the network through the usual transport protocols, that is, UDP (connectionless) and/or TCP (connection oriented).
Transporting the conversation: RTP
The RTP protocol offers a packet delivery service with audio and video information that has to be served in real time. This protocol uses UDP as its transport protocol in order to minimise the overhead (the UDP header is much smaller than TCP). In exchange for that it cannot guarantee the delivery of the packets it transports (UDP is not connection oriented, there is no retransmission of lost packets), nor can it guarantee that the order in which it delivers the packets is the correct one.
Structure of an RTP packet:

So what RTP tries to do is add those features that UDP does not give it in order for the data it transports to be as useful as possible. The features RTP gives to UDP are: QoS level, timestamps, sequence numbers and delivery confirmation for each packet sent. It can also support error correction schemes to make the data it transports more robust, even some basic encryption options for the data of the packet.
Obviously that loads the UDP packet a bit; in this diagram we can see a comparison with the price we pay for obtaining all these features.

RTP Control Protocol (RTCP)
RTCP is a protocol complementary to RTP and is used to send control information, such as the number of lost packets, jitter, delay, etc. It is very useful to know what the quality of the session we are maintaining is. Thanks to the information of this protocol we can know how much our network needs us to give it QoS support. Or the need to change the codecs we are using in order to adjust better to the needs of the network we are working on.
Codecs
At the very top of the VoIP stack we find the protocols in charge of compressing the information that has been sampled from the digitisation source (our voice, video images, etc.). The factors that determine the efficiency of a codec are: the compression level (the more it compresses the better), compression and decompression time (the less time the process takes the better), support for packet loss (ability to reproduce the original information without having all the packets at the destination), error correction, intellectual cost (bear in mind that not all codecs are free, many are paid).
Audio codecs:
- G.711 (year 1988) international standard for the encoding of telephone conversations. It uses 64kbps of bandwidth for each conversation.
- G.723.1 (year 1996) uses from 5.3 to 6.3kbps of bandwidth. It is capable of detecting voice inactivity, in order to consume less bandwidth, and it is also capable of generating comfort noise (noise needed to know that the call is in progress and that there are no problems on the line). It is quite good at supporting packet loss and at correcting erroneous bit errors. The family of international standards for transporting video H.324 establishes this audio protocol as the standard for audio.
- G.729 (year 1996) uses about 8kbps of bandwidth, but it can also work at 6.4kbps or 11.8kbps. It supports voice activity detection and comfort noise generation.
- GSM voice codecs known thanks to mobile telephony, defined by ETSI. The bandwidth they use to work is about 13kbps.
- Speex it is OpenSource and we developed it at xiph.org. Capable of working with 8, 16 and 32kHz samples. Capable of working with bandwidths from 2kpbs up to 44kbps. It is also resistant to network errors, it supports voice activity detection. It also supports variable-bit-rates, that is, it can adapt the sampling according to the complexity of the sounds to be sent, it is even capable of supporting stereo encoding.
To finish...
With this document we have already gone over, broadly speaking, the elements that make up a VoIP communication. When we set out to configure a VoIP system we will find many other acronyms, codecs, protocols, etc. but this document serves us as a basic reference to start working from while we gain experience in this very interesting world.