Networking Tutorial · Core Protocols · Lesson 10 of 28
UDP
UDP's fire-and-forget datagrams, when they beat TCP, and the protocols built on them (DNS, QUIC, video, games).
What UDP is
UDP (User Datagram Protocol) sends independent messages called datagrams, with no handshake, no retransmission and no ordering. Its header is just 8 bytes: source port, destination port, length and checksum.
| TCP | UDP | |
|---|---|---|
| Connection setup | Handshake | None |
| Reliability | Retransmits lost data | Lost datagrams stay lost |
| Ordering | Guaranteed | Not guaranteed |
| Unit | Byte stream | Individual messages |
| Used by | HTTP/1.1 and HTTP/2, SSH, databases | DNS, QUIC (HTTP/3), video calls, games, VoIP |
When UDP wins
- Small request/response exchanges such as DNS lookups: one packet each way, no handshake.
- Real-time media: a late video frame is useless, so retransmitting it only adds delay.
- Custom reliability: QUIC, the transport under HTTP/3, builds its own reliability and encryption on top of UDP so it can evolve faster than operating-system TCP stacks.
import random
random.seed(3)
LOSS = 0.2
sent = [f"frame-{i}" for i in range(1, 11)]
received = [f for f in sent if random.random() > LOSS]
print("received:", received)
print(f"{len(sent) - len(received)} of {len(sent)} datagrams lost; UDP doesn't resend them")
print("a video call just shows the next frame instead of waiting")
Output
received: ['frame-1', 'frame-2', 'frame-3', 'frame-4', 'frame-5', 'frame-8', 'frame-9', 'frame-10'] 2 of 10 datagrams lost; UDP doesn't resend them a video call just shows the next frame instead of waiting
Firewalls and UDP
Because UDP has no connection, stateful firewalls and NAT devices track UDP "flows" by timeouts instead. Many corporate networks block most UDP, which is why HTTP/3 clients always fall back to HTTP/2 over TCP.
Test yourself
Why do DNS lookups usually use UDP?
UDP is encrypted by defaultA lookup fits in one packet each way, so skipping the TCP handshake saves a round tripTCP cannot carry DNS dataUDP guarantees delivery
Show answer
Answer: A lookup fits in one packet each way, so skipping the TCP handshake saves a round trip
Small, independent request/response messages are UDP's sweet spot. DNS falls back to TCP for large responses and zone transfers.