UDP: fire and forget
UDP is the simplest way for two apps to talk over IP. It adds an 8-byte header with two ports, a length and a checksum, and then just sends. Follow a game on your laptop sending five numbered updates to a game server: no handshake, one update lost, two arriving out of order, and the game deciding what to do about it.
5 quick questions
Pick an answer to see why. Your score saves with your progress.
01How big is the UDP header?
Four fields of 2 bytes each: source port, destination port, length and checksum. That is everything UDP adds to IP.
02A datagram is dropped by a busy router. What does UDP do?
UDP has no acknowledgments, no timers and no retransmission. Any recovery is the application's job.
03Datagrams #1 to #5 are sent in order but arrive as #1, #4, #3, #5. What does the server's UDP hand to the game?
The UDP header has no sequence number, so UDP cannot reorder anything. The numbers in this figure are the game's own, inside its data.
04What does the UDP length field count?
Header plus data: 8 + 24 = 32 bytes here. The IP packet around it is 20 bytes more, 52 in total.
05Why does a live game prefer UDP over TCP?
TCP delivers bytes strictly in order, so one loss delays everything behind it by at least a round trip. For a position update, a newer one is better than a late old one.
Glossary
- UDP
- User Datagram Protocol (RFC 768): sends single messages between apps over IP with only ports, a length and a checksum added.
- Datagram
- One self-contained UDP message: the 8-byte header plus the data. Each one travels on its own.
- Port
- A 16-bit number that names which app on a computer a datagram is for, like 53 for DNS.
- Checksum
- A 16-bit check value over the header, data and IP addresses that lets the receiver spot damaged bits.
- Handshake
- Opening messages that set up a connection before any data, like TCP's SYN, SYN-ACK, ACK. UDP has none.
- Acknowledgment
- A reply saying "I got it". TCP uses them to resend lost data; UDP sends none.
- QUIC
- A newer transport protocol (RFC 9000) that runs inside UDP datagrams and adds its own reliability and encryption; HTTP/3 uses it.
Notes and sources
- 192.0.2.7 and 203.0.113.10 are RFC 5737 documentation addresses. Port 50000 is in the dynamic range 49152–65535 (RFC 6335); the game's port 4000 is illustrative.
- The #1 to #5 numbers are written by the game inside its own data. The UDP header has no sequence number.
- Over IPv4 a checksum of 0 means "not computed" and is allowed; over IPv6 the UDP checksum is mandatory (RFC 8200).
- A home router doing NAT would also rewrite the source address and port on the way out; that is left out here.
- QUIC (RFC 9000) runs inside UDP datagrams and adds connections, TLS 1.3 encryption, acknowledgments and retransmission itself.
Quiz Unlocks after the last step.