← Module 04 · Layer 4: Transport

UDP Header & Use Cases

UDP (User Datagram Protocol) doesn't fail at being TCP. It deliberately leaves out everything TCP (Transmission Control Protocol) adds, and that's exactly why certain applications choose it on purpose.

The deliberately minimal alternative

If TCP's header is a certified-mail envelope with tracking, delivery confirmation, and enough bookkeeping to detect and refix a lost carton, UDP is a postcard: address on the front, message on the back, dropped in the mail, and the sender simply moves on. No handshake, no acknowledgment, no retransmission, no ordering guarantee, no congestion backoff. If a UDP datagram doesn't arrive, or arrives out of order, or arrives twice, UDP itself will never notice, tell anyone, or fix it. Any application that cares has to handle that itself, or decide it doesn't matter.

Source Port Destination Port Length Checksum 8 bytes total, always, no matter how much data follows
The entire UDP header. Compare this to TCP's 20-byte minimum: there's no sequence number, no acknowledgment number, no window size, nothing tracking state at all.
FieldSizeWhat it holds
Source Port16 bitsThe sending application's port; can be all zeros if no reply is expected
Destination Port16 bitsThe receiving application's port, e.g. 53 for DNS (Domain Name System)
Length16 bitsSize of the UDP header plus data, in bytes
Checksum16 bitsIntegrity check covering the header, data, and parts of the IP header; optional in IPv4, mandatory in IPv6

TCP versus UDP, side by side

TCPUDP
Connection setupThree-way handshake requiredNone, just send
Delivery guaranteeReliable, retransmits lost segmentsBest effort, nothing retransmitted
OrderingGuaranteed, reassembled in orderNot guaranteed
Congestion controlBuilt in (see Flow & Congestion Control)None; the application must self-limit if it needs to
Header size20 bytes minimum8 bytes, fixed
Typical usesHTTP/HTTPS, SSH, file transfer, emailDNS, DHCP, VoIP, video conferencing, online gaming

Why anything would choose less reliability

WHY DNS SOMETIMES SWITCHES TO TCP ANYWAY

DNS defaults to UDP, but falls back to TCP when a response is too large for a single UDP datagram (historically 512 bytes, larger with the EDNS0 extension), and always uses TCP for zone transfers between DNS servers. UDP has no mechanism of its own for splitting a response across multiple datagrams and reassembling it, so anything that genuinely needs that borrows TCP instead.