The idea: two protocols, two paths

A phone call over the internet uses two protocols. SIP (Session Initiation Protocol) sets the call up and tears it down: "Bob, Alice is calling", "ringing", "answered", "hung up". RTP (Real-time Transport Protocol) carries the voice itself, a small packet every 20 ms. They take different paths. SIP messages go through a SIP proxy, because Alice's phone does not know where Bob's phone is. The voice goes straight from phone to phone, because the INVITE and the 200 OK that answers it carry an SDP body with each phone's IP address and port for audio.

Alice's phone and Bob's phone at the bottom corners, the SIP proxy at the top. SIP messages go from Alice to the proxy and from the proxy to Bob. A green RTP line goes straight from Alice's phone 192.0.2.101:49170 to Bob's phone 192.0.2.201:3456, below the proxy.
SIP finds Bob through the proxy; RTP then goes straight between the two IP:port pairs from the SDP.

Setting up the call

Alice's phone sends an INVITE to its proxy. The proxy answers 100 Trying at once, so Alice's phone stops resending the INVITE over UDP. The proxy knows where Bob is from his earlier REGISTER, and forwards the INVITE to 192.0.2.201. Bob's phone rings and sends 180 Ringing. When Bob picks up, it sends 200 OK. Alice's phone confirms with ACK (Demo: a whole call, INVITE to BYE).

Time-down ladder with three lines, Alice, proxy and Bob: INVITE Alice to proxy, 100 Trying back, INVITE proxy to Bob, 180 Ringing Bob to proxy to Alice, 200 OK Bob to proxy to Alice, ACK Alice straight to Bob, then RTP both ways straight between the phones, then BYE and 200 OK straight between the phones.
The first seven messages pass the proxy; the ACK, the RTP and the BYE go phone to phone.

Responses have a three-digit status code, as in HTTP. A 1xx code is provisional: "still working on it". A 2xx to 6xx code is final and ends the INVITE.

CodeMeaningOn this page
100 Tryingthe next hop has the requestproxy → Alice
180 Ringingthe callee's phone is ringingBob → proxy → Alice
200 OKanswered (or: request done)Bob → proxy → Alice; also for BYE and CANCEL
486 Busy Herethe callee is busyDemo: Bob is busy
487 Request Terminatedthe INVITE was cancelledDemo: no answer

Three header values name the call: the Call-ID, the From tag Alice picks and the To tag Bob adds in his 180. Together they identify the dialog. CSeq counts the requests in it: 1 INVITE, then 2 BYE.

SDP: the offer and the answer

The INVITE carries the SDP offer, the 200 OK the SDP answer (RFC 3264). The lines that matter for the audio are c= (the IP address) and m= (the port and the list of payload types). The canvas shows them in green.

LineOffer (Alice)Answer (Bob)
c=IN IP4 192.0.2.101IN IP4 192.0.2.201
m=audio 49170 RTP/AVP 0 8 101audio 3456 RTP/AVP 0 101
a=rtpmap0 PCMU/8000, 8 PCMA/8000, 101 telephone-event/80000 PCMU/8000, 101 telephone-event/8000
a=ptime20 (ms of audio per packet)20

Bob's answer keeps only codecs from the offer, so both phones send PCMU (G.711 µ-law, payload type 0). Payload type 101 carries keypad digits (DTMF). Alice's phone may start sending audio only once it has the answer: before it, Alice does not know Bob's port.

What the proxy changes, and what it skips

A proxy forwards requests and responses. On the INVITE to Bob it puts its own Via on top (so the responses come back through it), lowers Max-Forwards from 70 to 69 (a loop guard) and replaces the Request-URI with Bob's registered address. On each response it removes its own Via and sends it to the next one. The canvas shows these changed lines in blue.

Bob's 200 OK has a Contact header: sip:bob@192.0.2.201. This proxy does not add a Record-Route header, so it asks to leave the path. The ACK for the 200 OK and the BYE go straight to the Contact address. The proxy only saw the first seven messages, and never any audio.

RTP: a packet every 20 ms

Each RTP packet has a 12-byte header and 160 bytes of audio: 20 ms at 8000 samples per second is 160 samples, one byte each in PCMU. With the 8-byte UDP header and the 20-byte IP header, a packet is 200 bytes. 50 packets a second each way is 80 kbit/s.

The 12-byte RTP header in three 32-bit rows: version 2, padding, extension, CSRC count, marker, payload type 0, sequence number 8000; timestamp 160000; SSRC 0x1A2B3C4D. Below: the next packet has sequence number 8001 and timestamp 160160.
From one packet to the next, the sequence number goes up by 1 and the timestamp by 160 samples.
  • Payload type (PT): which codec, as agreed in the SDP (0 = PCMU).
  • Sequence number: +1 per packet. The receiver sees a lost or reordered packet as a gap (Demo: a lost RTP packet).
  • Timestamp: the sampling time of the first sample, in clock units (8000 per second): +160 per packet. It tells the receiver when to play each packet.
  • SSRC: a random number naming the sender's stream.

RTP runs over UDP. A lost packet is not resent: by the time a resend arrived it would be too late to play. The receiver fills the 20 ms gap with a guess (packet loss concealment) and plays the next packets from its jitter buffer.

RTCP reports

Next to each RTP port the phone opens the RTP port + 1 for RTCP. About every 5 seconds each phone sends a sender report (SR): how many packets and how many audio bytes it sent, and a report block on the stream it receives. That block has the fraction lost since the last report (lost ÷ expected, as a number out of 256), the cumulative number lost, the highest sequence number received, and the jitter. In the demo, 1 packet out of 250 is lost: floor(256 × 1 / 250) = 1, so the fraction lost is 1/256.

Busy, no answer, and the ACK for a failure

If Bob is on another call, his phone answers the INVITE with 486 Busy Here (Demo: Bob is busy, 486 Busy Here). If nobody picks up, Alice gives up and her phone sends CANCEL. The CANCEL is answered 200 OK hop by hop, and Bob's phone then ends the INVITE with 487 Request Terminated (Demo: no answer, Alice sends CANCEL).

Every final response to an INVITE gets an ACK, but not the same way. For a 2xx, the caller sends the ACK end to end, as a new request in the dialog. For a failure (3xx to 6xx), each hop sends its own ACK to the hop before it: the proxy acknowledges Bob's 486 itself, then Alice acknowledges the proxy's 486. In both failure cases no RTP is ever sent.

See also How a WebRTC Call Gets Through NATs: the same SDP offer and answer, but with ICE candidates, because phones behind NAT cannot just send to the private address in c=.

See also the jitter buffer for how the receiving phone plays RTP packets that arrive unevenly, and TCP vs UDP for why voice goes over UDP.

What the page leaves out

NAT traversal (a phone behind NAT puts a private address in its SDP; real setups use STUN, ICE, or a media relay in the proxy), encryption (SIP over TLS on port 5061, SRTP for the media), REGISTER and digest authentication (401/407), Record-Route and proxies that stay in the path, forking to several phones, retransmission timers (Timer A, B), early media in 183 Session Progress, re-INVITE for hold or a codec change, the jitter value in RTCP, and codecs other than G.711 (G.722, Opus).

On the mind map

This page on the Networking mind map · 83 pages in 10 branches · open it to see the whole map and test yourself in recall mode.