16.1 The RTP header
SIP and SDP agree where the voice goes and how it is coded. RTP carries it: a stream of small UDP packets, usually one every 20 ms in each direction, directly between the two media endpoints (Module 15).
“This memorandum specifies the real-time transport protocol (RTP), which provides end-to-end delivery services for data with real-time characteristics, such as interactive audio and video.”Read the section ↗
Every RTP packet starts with a 12-byte header:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|V=2|P|X| CC |M| PT | sequence number |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| timestamp |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| synchronization source (SSRC) identifier |
+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
| contributing source (CSRC) identifiers |
| .... |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
“The first twelve octets are present in every RTP packet, while the list of CSRC identifiers is present only when inserted by a mixer.”Read the section ↗
| Field | Bits | Meaning | Typical value |
|---|---|---|---|
| V | 2 | Version | Always 2 |
| P | 1 | Padding at the end | 0; 1 with some encryption |
| X | 1 | A header extension follows | 0 for classic SIP; 1 in WebRTC |
| CC | 4 | Number of CSRCs | 0, unless a mixer sends it |
| M | 1 | Marker | 1 on the first packet after silence, and on the first packet of a DTMF event |
| PT | 7 | Payload type: which codec | 0 (PCMU), 8 (PCMA), 101 (telephone-event)… from the SDP |
| Sequence number | 16 | +1 for each packet | Random start; wraps at 65535 |
| Timestamp | 32 | Sampling instant, in clock ticks | Random start; +160 every 20 ms at 8000 Hz |
| SSRC | 32 | The name of this stream | Random |
| CSRC | 32 each | The sources that a mixer combined | Only in conferences |
“The sequence number increments by one for each RTP data packet sent, and may be used by the receiver to detect packet loss and to restore packet sequence.”Read the section ↗
“The SSRC field identifies the synchronization source. This identifier SHOULD be chosen randomly, with the intent that no two synchronization sources within the same RTP session will have the same SSRC identifier.”Read the section ↗
SSRCSSRC. The random 32-bit number in each RTP packet that names the stream it belongs to., sequence number, and timestamp each start at a random value, so a capture of two calls never shows the same numbers. Select each field, or paste the UDP payload of an RTP packet from Wireshark:
RTP header · RFC 3550 §5.1
Twelve bytes in front of every 20 ms of voice
- RTP
- ⚠Problem
12 bytes of header, 160 bytes of payload
Payload type · Fixed header · 7 bits
0 (PCMU)
0000000
Payload type 0: PCMU, a static number of the RTP/AVP profile.
“This field identifies the format of the RTP payload and determines its interpretation by the application.” RFC 3550 §5.1 ↗
The payload type is the only link between a packet and the SDP: PT=101 means telephone-event only because the SDP said a=rtpmap:101 telephone-event/8000. A receiver drops packets with a payload type it does not know:
“A receiver MUST ignore packets with payload types that it does not understand.”Read the section ↗
16.2 Clock rate, timestamp, and packet time
The timestamp counts samples, not milliseconds. Its clock rate comes from the codec: 8000 Hz for G.711, 48000 for Opus, 90000 for video.
“The timestamp reflects the sampling instant of the first octet in the RTP data packet.”Read the section ↗
timestamp step = clock rate × packet time
G.711, 20 ms = 8000 × 0.020 = 160
Opus, 20 ms = 48000 × 0.020 = 960
packets/second = 1000 / packet time = 50
“If an audio application reads blocks covering 160 sampling periods from the input device, the timestamp would be increased by 160 for each such block, regardless of whether the block is transmitted in a packet or dropped as silent.”Read the section ↗
The timestamp keeps counting during silence, even when no packets are sent. So the receiver can tell the two cases apart:
| Sequence number | Timestamp | What happened |
|---|---|---|
| 1001 → 1002 | +160 | Normal: the next 20 ms |
| 1001 → 1003 | +320 | One packet lost |
| 1001 → 1002 | +4800 | No loss: 600 ms of silence was not sent |
| 1002 → 1001 | −160 | Reordered: the network swapped two packets |
The packet time (a=ptime in the SDP) is how much audio goes in one packet. 20 ms is the default:
“For packetized audio, the default packetization interval SHOULD have a duration of 20 ms or one frame, whichever is longer, unless otherwise noted in Table 1 (column "ms/packet").”Read the section ↗
“The packetization interval determines the minimum end-to-end delay; longer packets introduce less header overhead but higher delay and make packet loss more noticeable.”Read the section ↗
16.3 Codecs: G.711, G.722, G.729, Opus, AMR-WB, EVS
| Codec | Payload type | RTP clock | Bit rate | Audio band | Where |
|---|---|---|---|---|---|
| G.711 (PCMU, PCMA) | 0, 8 | 8000 | 64 kbit/s | Narrowband, 300–3400 Hz | Everywhere. The common denominator of trunks and gateways |
| G.722 | 9 | 8000 | 64 kbit/s | Wideband, 50–7000 Hz | HD voice on desk phones |
| G.729 | 18 | 8000 | 8 kbit/s | Narrowband | Older trunks and WAN links. Poor for in-band DTMF and fax |
| Opus | dynamic | 48000 | 6–510 kbit/s | Narrowband to fullband | WebRTC, softphones. Built for packet loss |
| AMR-WB | dynamic | 16000 | 6.6–23.85 kbit/s | Wideband | VoLTE HD voice (Module 27) |
| EVS | dynamic | 16000 | 5.9–128 kbit/s | Up to fullband | Newer VoLTE |
Two clock rates surprise people. G.722 samples at 16 kHz, but its RTP clock is 8000:
“Even though the actual sampling rate for G.722 audio is 16,000 Hz, the RTP clock rate for the G722 payload format is 8,000 Hz because that value was erroneously assigned in RFC 1890 and must remain unchanged for backward compatibility.”Read the section ↗
And Opus always says opus/48000/2 in the SDP, and counts its timestamp at 48000, whatever rate it really uses.
Narrowband sounds like a phone; wideband (“HD voice”) sounds like a person in the room. A call is only as good as its worst leg: a wideband call that crosses a G.711 trunk is narrowband from end to end. And each change of codec — transcoding, in a gateway or SBC — adds delay and loses quality.
16.4 Jitter, loss, delay, and the jitter buffer
Packets leave every 20 ms, but they do not arrive every 20 ms. Queues in routers, Wi-Fi, and busy links add a different delay to each one. That variation is jitterjitter. The variation in packet delay. Packets sent every 20 ms arrive 12, 31, 18 ms apart..
“The interarrival jitter J is defined to be the mean deviation (smoothed absolute value) of the difference D in packet spacing at the receiver compared to the sender for a pair of packets.”Read the section ↗
| Problem | Cause | What the caller hears |
|---|---|---|
| Delay | Distance, queues, the jitter buffer, the codec | Both talk at once. Above about 150 ms one way, conversation becomes hard (ITU-T G.114) |
| Jitter | A different queueing delay for each packet | Nothing, if the jitter buffer absorbs it; gaps, if it does not |
| Loss | Congestion, Wi-Fi, a full queue | Clicks and missing syllables. Codecs hide a little loss; Opus hides more |
The receiver’s jitter bufferjitter buffer. A queue in the receiver that holds packets for a short time, so that they can be played at an even pace. holds each packet for a short time, then plays the packets at an even pace. A deeper buffer saves more late packets, but adds its depth to the delay of every packet. A packet that arrives after its playout time is useless: the receiver throws it away, so a late packet is as bad as a lost one. Change the network and the buffer, and see the trade-off:
Jitter buffer · 150 packets, 20 ms each
How deep should the buffer be?
- Played
- Late
- Lost
Some gaps: the codec hides a few, but people hear clicks. A deeper buffer saves late packets, but every millisecond of buffer is a millisecond of delay.
Most phones use an adaptive buffer: it grows when the jitter grows, and shrinks when the network is calm. It changes its depth at the start of a talkspurt, when the marker bit is set, so that the change falls in a silence. RTCP reports the jitter that the receiver measures (Module 17).
16.5 DTMF: RFC 4733 events, SIP INFO, or in-band
There are three ways to send a key that the caller presses:
| Method | How | Good | Bad |
|---|---|---|---|
| RFC 4733 events | telephone-event RTP packets in the voice stream |
Exact; works with every codec; the standard | Both sides must list telephone-event in the SDP (Module 15) |
| SIP INFO | One INFO request per key, usually application/dtmf-relay |
Easy for application servers to read | Not standardised; every proxy and B2BUA on the route must pass it; slower |
| In-band | The tones inside the audio | Needs nothing in the signaling | Works only with G.711; compressed codecs distort the tones |
An RFC 4733 event is a 4-byte payload: the key, an end bit, a volume, and a duration. The first packet of each key has the marker bit; updates keep the same timestamp and a longer duration; the last packet, with the end bit, goes three times.
“The update packets MUST have the same RTP timestamp value as the initial packet for the event, but the duration MUST be increased to reflect the total cumulative duration since the beginning of the event.”Read the section ↗
“The final packet for each event and for each segment SHOULD be sent a total of three times at the interval used by the source for updates.”Read the section ↗
RFC 4733 events
DTMF as RFC 4733 telephone-events
- RTP media
The IVR plays its menu. Alice presses 5 on her keypad.
All steps as text
- Alice → IVR: RTP audio. The IVR plays its menu. Alice presses 5 on her keypad.
- Alice → IVR: RTP event 5 (start). The phone sends a telephone-event packet with the marker bit set. Payload type 101, from the SDP.
- Alice → IVR: RTP event 5 (update). Updates every 20 ms: the same timestamp, a longer duration. The IVR knows the key at once.
- Alice → IVR: RTP event 5 (end, ×3). Alice releases the key. The phone sends the final packet, with E=1, three times: one copy may go missing.
- Alice → IVR: RTP audio. Voice packets continue, with the next sequence numbers. The IVR reads one digit: 5.
“Companies have been using INFO messages in order to transport Dual-Tone Multi-Frequency (DTMF) tones. All mechanisms are proprietary and have not been standardized.”Read the section ↗
Both sides must use the same method. A phone that sends INFO to a gateway that waits for RFC 4733 events sends digits that nobody reads.
16.6 Comfort noise and silence suppression
In a normal conversation, each side is silent more than half the time. With silence suppression (VAD, voice activity detection), a phone stops sending RTP while its user is silent, and saves that bandwidth.
“Receivers MUST assume that senders may suppress silence unless this is restricted by signaling specified elsewhere.”Read the section ↗
Total silence sounds like a dropped call, so the sender first sends a comfort noisecomfort noise. Soft background noise that the receiver plays during silence, so the line does not sound dead. packet: a description of its background noise, in a byte or a few bytes. The receiver plays similar noise until speech returns. The first voice packet after the silence has the marker bit set.
“At the beginning of an inactive voice segment (silence period), a CN packet is transmitted in the same RTP stream and indicated by the CN payload type.”Read the section ↗
“For applications which send either no packets or occasional comfort-noise packets during silence, the first packet of a talkspurt, that is, the first packet after a silence period during which packets have not been transmitted contiguously, SHOULD be distinguished by setting the marker bit in the RTP data header to one.”Read the section ↗
| Codec | Comfort noise |
|---|---|
| G.711, G.722 | The generic CN payload: payload type 13 (m=audio 49170 RTP/AVP 0 13) |
| G.729 | Its own, Annex B. a=fmtp:18 annexb=no turns it off |
| Opus, AMR-WB, EVS | Built in (DTX) |
Silence suppression saves bandwidth, but it clips the first syllable when the detector is slow, and it can confuse fax and modem calls. Many trunks turn it off.
16.7 Symmetric RTP and latching
A phone behind a NAT router writes its private address in the SDP (Module 15). An SBC on the public side cannot send to that address. But it can see where the phone’s RTP comes from: the public address and port of the NAT mapping. The SBC sends its RTP back to that address. This is latchinglatching. An SBC sends media back to the address and port that the media came from, not to the address in the SDP..
Latching works only if the phone sends RTP from the same port where it receives RTP: symmetric RTPsymmetric RTP. Sending RTP from the same address and port where it is received. NAT routers and SBCs need it.. Then the NAT mapping that its outgoing packets created also brings the incoming packets back to the right port.
“A device supports symmetric RTP if it selects, communicates, and uses IP addresses and port numbers such that, when receiving a bidirectional RTP media stream on UDP port "A" and IP address "a", it also transmits RTP media for that stream from the same source UDP port "A" and IP address "a".”Read the section ↗
Symmetric RTP
Symmetric RTP: the SBC latches and the audio returns
- RTP media
Alice's SDP said 192.168.1.20:49170. Her phone also sends from 49170: symmetric RTP.
All steps as text
- Alice → NAT router: RTP from port 49170. Alice's SDP said 192.168.1.20:49170. Her phone also sends from 49170: symmetric RTP.
- NAT router → SBC: RTP from port 40200. The NAT router maps 192.168.1.20:49170 to its public port 40200.
- SBC → NAT router: RTP to port 40200. The SBC ignores the private address in the SDP. It latches: it sends to the source of the media.
- NAT router → Alice: RTP to port 49170. The NAT mapping leads back to 49170, where the phone listens. Audio flows both ways.
“For these reasons, it is RECOMMENDED that symmetric RTP and symmetric RTCP always be used for bidirectional RTP media streams.”Read the section ↗
Latching trusts the first packet that arrives, so an attacker who sends RTP to the SBC’s port first can take over the stream. SBCs limit this: they latch only to the address in the signaling, or only at the start, or only with SRTP. Module 20 covers NAT traversal with STUN, TURN, and ICE.
16.8 How to calculate bandwidth
The codec rate is only the payload. Every packet also carries an RTP, a UDP, and an IP header, and on a LAN an Ethernet header. At 20 ms there are 50 packets a second in each direction, so the headers add up:
G.711, 20 ms, IPv4, Ethernet
payload 160 bytes (64 kbit/s × 20 ms ÷ 8)
RTP 12
UDP 8
IPv4 20
Ethernet 18 (14 header + 4 FCS)
---
218 bytes × 50 packets/s × 8 = 87.2 kbit/s in each direction
| Codec, 20 ms | Codec rate | IP | Ethernet | Ethernet on the wire |
|---|---|---|---|---|
| G.711 | 64 | 80 | 87.2 | 95.2 |
| G.729 | 8 | 24 | 31.2 | 39.2 |
For G.729, the headers are twice as big as the voice. A longer packet time saves headers but adds delay: G.729 at 40 ms needs 16 kbit/s at the IP layer, not 24. SRTP adds a 10-byte authentication tag, and IPv6 adds 20 bytes to the IP header.
Bandwidth calculator
What does one call really use?
- Voice
- Headers
G.711 (PCMU/PCMA) · 64 kbit/s · narrowband, 300–3400 Hz · No compression: every phone and gateway has it.
| Layer | Bytes per packet | kbit/s |
|---|---|---|
| Codec payload | 160 | 64.0 |
| RTP header | 12 | 4.8 |
| UDP header | 8 | 3.2 |
| IPv4 header | 20 | 8.0 |
| Ethernet | 18 | 7.2 |
| One packet | 218 | 87.2 |
Common mistakes
Reading an SSRC, sequence, or timestamp jump as an error
An engineer looks at a capture and sees the SSRC change in the middle of a call, and the sequence number and timestamp jump to new random values. It looks like a broken stream. Usually it is not: a transfer, a re-INVITE to a new media server, a switch from early media to the answered call, or an SBC that changed its media relay starts a new stream, and a new stream has new random values.
seq timestamp SSRC from
4012 2412560160 0x3a5f12c4 203.0.113.30 IVR menu
4013 2412560320 0x3a5f12c4 203.0.113.30
---- transfer to an agent: re-INVITE with new SDP ----
51877 884210400 0x9e04b7d1 203.0.113.44 a new source
51878 884210560 0x9e04b7d1 203.0.113.44 +1, +160: normal again“If a source changes its source transport address, it must also choose a new SSRC identifier to avoid being interpreted as a looped source (see Section 8.2).”Read the section ↗
Remember: check what happened in the signaling at that moment. A jump with a new SSRC, a new source address, or a re-INVITE just before it is a new stream, not loss. A jump in the sequence number with the same SSRC and source is real loss. A receiver must follow the new SSRC; one that does not gives one-way audio after a transfer.
Planning bandwidth from the codec rate only
A site needs 30 simultaneous G.711 calls. The plan says 30 × 64 kbit/s = 1.9 Mbit/s, and a 2 Mbit/s link looks fine. But each call uses 87.2 kbit/s on Ethernet in each direction, so 30 calls need 2.6 Mbit/s: calls break up as soon as the office is busy. With G.729 the error is bigger: 8 kbit/s on paper, 31.2 on Ethernet.
Remember: plan with the packet size, not the codec rate: payload plus 12 (RTP) + 8 (UDP) + 20 (IPv4) or 40 (IPv6) + 18 (Ethernet), times the packets per second. Add SRTP and VPN headers if they are used, and leave room for RTCP and signaling. Use the calculator above.
DTMF sent both in-band and as RFC 4733 events
The phone sends telephone-event packets for each key, but it also leaves the tones in the G.711 audio. An IVR that listens for both detects each key twice: the caller presses 5 and the IVR reads 55. Or the gateway that converts events back to tones plays them over the tones that are already in the audio.
Broken: tones and events
DTMF as audio and as events
- RTP media
- ⚠Problem
The IVR plays its menu. Alice presses 5 on her keypad.
All steps as text
- Alice → IVR: RTP audio. The IVR plays its menu. Alice presses 5 on her keypad.
- Alice → IVR: RTP audio with tone 5. The phone also leaves the tone in the audio: 770 Hz and 1336 Hz, the two tones of key 5.
- Alice → IVR: RTP event 5 (start). The same key also goes as a telephone-event, with the same timestamp.
- Alice → IVR: RTP event 5 (end, ×3). The event ends normally. Problem: The IVR detects 5 in the audio and 5 as an event: it reads 55.
“It is RECOMMENDED that gateways render only the telephone-event payload once it is received, since the audio may contain spurious tones introduced by the audio compression algorithm.”Read the section ↗
Remember: choose one method for each call and configure it on both sides. With RFC 4733, the sender removes the tones from the audio, and the receiver ignores in-band detection. Phones and gateways call this setting “DTMF mode”: RFC 2833 (the old number of RFC 4733), in-band, INFO, or auto.
Summary
- RTP carries the media in UDP packets with a 12-byte header: version, padding, extension, CSRC count, marker, payload type, sequence number, timestamp, and SSRC.
- The payload type links a packet to the SDP. The sequence number goes up by one per packet; the timestamp counts samples at the codec’s clock rate (+160 every 20 ms at 8000 Hz). Both start at random values.
- Common codecs: G.711 and G.722 (64 kbit/s), G.729 (8), Opus (variable, clock 48000), AMR-WB and EVS (VoLTE).
- Jitter is the variation of delay. A jitter buffer trades delay for fewer late packets; a late packet is as bad as a lost one.
- DTMF goes as RFC 4733 events (the standard), SIP INFO, or in-band tones. Use one method, on both sides.
- Comfort noise fills the silence when a phone stops sending. The first packet after it has the marker bit.
- Symmetric RTP lets an SBC latch to the public address of a phone behind NAT.
- Bandwidth includes every header: G.711 at 20 ms is 80 kbit/s at IP and 87.2 on Ethernet, in each direction.