What is in a UDP header, and what does UDP leave to the application?
Show the answer
Say this first
Eight bytes: source port, destination port, length (header plus data) and checksum, 16 bits each. UDP leaves everything else to the application: no handshake, no acknowledgment, no retransmission, no ordering, no flow control and no congestion control. The checksum is optional in IPv4 (zero means none) and mandatory in IPv6, apart from narrow tunnel exceptions.
Go deeper
Fields
| Field | Bits | Notes |
|---|---|---|
| Source port | 16 | May be 0 if no reply is expected, rarely seen |
| Destination port | 16 | Selects the application |
| Length | 16 | Header plus payload, minimum 8 |
| Checksum | 16 | Covers a pseudo-header, the header and the data |
Sizes
The largest UDP payload over IPv4 is 65,507 bytes (65,535 minus 20 for IP and 8 for UDP). Anything over the path MTU is fragmented by IP, and losing one fragment loses the whole datagram. That is why DNS over UDP now aims for answers of about 1,232 bytes and QUIC sizes its own packets.
What runs on UDP
DNS 53, DHCP 67 and 68, TFTP 69, NTP 123, SNMP 161 and 162, syslog 514, IKE 500 and NAT-T 4500, RIP 520, BFD 3784, VXLAN 4789, QUIC and HTTP/3 on 443, RTP media on dynamic ports.
What the application must add
Timeouts and retries (DNS, TFTP), sequence numbers (RTP), its own rate control (RFC 8085 sets out guidelines for UDP applications), and keepalives to hold NAT and firewall state open.
They will ask next
Why does TFTP work without TCP?
It is lock-step: every 512-byte data block (the default) is acknowledged before the next is sent, and the sender retransmits on timeout. It is reliable but slow, one block per round trip.
Why do tunnels like VXLAN use UDP rather than raw IP?
A UDP header gives a source port the encapsulating device can set from a hash of the inner flow. Routers that do ECMP on the five-tuple then spread tunnel traffic across paths. UDP also crosses NAT and firewalls more easily than a new IP protocol.
Traps
- Saying UDP has no checksum. It has one; IPv4 lets it be zero, IPv6 normally requires it.