Home/Learn/Computer Networks/UDP — User Datagram Protocol

UDP — User Datagram Protocol

Beginner
Transport Layer

UDP is a connectionless, unreliable transport protocol that sacrifices guaranteed delivery for low overhead and minimal latency — ideal for DNS, video streaming, gaming, and QUIC.

Overview

While TCP provides reliability through connection management, acknowledgements, and retransmission, UDP does none of that. A UDP datagram is sent and forgotten — no handshake, no ACKs, no retransmission, no ordering guarantee. The entire UDP header is just 8 bytes (vs. TCP's 20 bytes minimum). This simplicity makes UDP extremely fast and ideal for latency-sensitive applications where occasional packet loss is acceptable: DNS (query-response fits in one datagram), video streaming (a dropped frame is better than a stalled stream), gaming (old position updates are worthless when a new one arrives), and VoIP. Modern protocols like QUIC (HTTP/3) are built on UDP, implementing their own reliability and multiplexing at the application layer — getting the best of both worlds.

UDP Header and Characteristics

UDP's 8-byte header contains just source port, destination port, length, and checksum. No sequence numbers, no acknowledgements, no connection state. Each datagram is independent — the receiver cannot ask for a retransmission.

UDP header structure and Java DatagramSocket
// UDP Header (8 bytes):
// ┌─────────────────┬─────────────────┐
// │ Source Port (2B)│ Dest Port (2B)  │
// ├─────────────────┼─────────────────┤
// │ Length (2B)     │ Checksum (2B)   │
// ├─────────────────┴─────────────────┤
// │ Data (variable)                   │
// └───────────────────────────────────┘
// Total overhead: 8 bytes (vs TCP's 20B minimum)

// Java UDP server:
DatagramSocket server = new DatagramSocket(5353);
byte[] buf = new byte[512];
DatagramPacket packet = new DatagramPacket(buf, buf.length);
server.receive(packet);                         // blocks until a datagram arrives
String msg = new String(packet.getData(), 0, packet.getLength());

// Java UDP client:
DatagramSocket client = new DatagramSocket();
byte[] data = "hello".getBytes();
InetAddress addr = InetAddress.getByName("localhost");
DatagramPacket send = new DatagramPacket(data, data.length, addr, 5353);
client.send(send);                              // fire and forget — no confirmation

When to Use UDP and QUIC

UDP is chosen when the application can tolerate or handle loss, when data is time-critical, or when the request-response fits in a single datagram. QUIC (used by HTTP/3) is built on UDP and implements its own multiplexing and selective reliability — eliminating TCP's head-of-line blocking.

UDP use cases and QUIC advantages
// Use UDP when:
// ✓ DNS lookups      — query fits in 1 datagram, response usually too
// ✓ Video/audio streaming — 1 dropped frame < paused stream
// ✓ Online gaming    — position updates are time-sensitive; stale = worthless
// ✓ DHCP             — client has no IP yet, can't use TCP
// ✓ NTP (time sync)  — single packet exchange, low overhead
// ✓ QUIC / HTTP/3    — implements own reliability on top of UDP

// QUIC advantages over TCP+TLS:
// 1. 0-RTT or 1-RTT connection establishment (vs 2-RTT for TCP+TLS 1.2)
// 2. Multiplexed streams — no head-of-line blocking (one lost packet
//    blocks the whole TCP stream; QUIC streams are independent)
// 3. Connection migration — connection survives IP change (e.g. Wi-Fi → 4G)

// DNS over UDP example:
// Client → UDP port 53 → DNS server
// Query: "What is the IP of api.example.com?"
// Response: "192.0.2.1"  (usually < 512 bytes, fits in one datagram)
// If response > 512 bytes (DNSSEC), falls back to TCP

Key Points to Remember

  • 1UDP is connectionless — no handshake, no ACKs, no retransmission, no ordering guarantee.
  • 2UDP header is 8 bytes; TCP is 20 bytes minimum — UDP has less overhead.
  • 3Best for: DNS, video streaming, VoIP, gaming, NTP, DHCP.
  • 4QUIC (HTTP/3) is built on UDP — adds reliability and multiplexing without TCP's head-of-line blocking.
  • 5Each UDP datagram is independent — datagrams can arrive out of order or not at all.
  • 6UDP checksum is optional in IPv4 but mandatory in IPv6.

Interview Questions

Sign in to ask Aria
1

What is the difference between TCP and UDP?

EasyTCS
2

Why is DNS typically over UDP and not TCP?

EasyInfosys
3

Why is UDP used for video streaming despite being unreliable?

MediumHotstar
4

What is QUIC and why is it built on UDP instead of TCP?

HardGoogle
5

What are the trade-offs between building reliability on top of UDP vs using TCP?

HardAmazon

Ask Aria about UDP — User Datagram Protocol

Your personal AI tutor — ask anything about this concept

Revision Status

Personal Notes

Sign in to save personal notes for this topic.

Discussion

Sign in to join the discussion.

Loading discussion…