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.
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).
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.
| Code | Meaning | On this page |
|---|---|---|
| 100 Trying | the next hop has the request | proxy → Alice |
| 180 Ringing | the callee's phone is ringing | Bob → proxy → Alice |
| 200 OK | answered (or: request done) | Bob → proxy → Alice; also for BYE and CANCEL |
| 486 Busy Here | the callee is busy | Demo: Bob is busy |
| 487 Request Terminated | the INVITE was cancelled | Demo: 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.
| Line | Offer (Alice) | Answer (Bob) |
|---|---|---|
c= | IN IP4 192.0.2.101 | IN IP4 192.0.2.201 |
m= | audio 49170 RTP/AVP 0 8 101 | audio 3456 RTP/AVP 0 101 |
a=rtpmap | 0 PCMU/8000, 8 PCMA/8000, 101 telephone-event/8000 | 0 PCMU/8000, 101 telephone-event/8000 |
a=ptime | 20 (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.
- 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).