UDP

User Datagram Protocol providing connectionless, best-effort data delivery for real-time applications

UDP (User Datagram Protocol)

  • Connectionless transport layer protocol that provides unreliable data delivery without error recovery or flow control
  • Operates at Layer 4 (Transport) of OSI model, serving as lightweight alternative to TCP
  • Uses simple best-effort delivery - sends data and hopes it arrives (no acknowledgments or retransmissions)
  • Adds minimal overhead with only 8-byte header compared to TCP’s 20+ byte header

Key Characteristics

  • No connection establishment - immediately sends data without handshake process
  • No reliability mechanisms - no sequence numbers, acknowledgments, or automatic retransmission
  • No flow control - sender transmits at whatever rate it chooses
  • No congestion control - doesn’t adjust transmission rate based on network conditions
  • Stateless - each datagram is independent with no relationship to previous/future datagrams

UDP Header Structure

Field Size Purpose
Source Port 16 bits Sending application’s port number
Destination Port 16 bits Receiving application’s port number
Length 16 bits UDP header + data length (minimum 8 bytes)
Checksum 16 bits Error detection for header and data

When UDP is Preferred

  • Real-time applications where speed matters more than reliability (VoIP, video streaming, online gaming)
  • DNS queries - simple request/response doesn’t justify TCP overhead
  • DHCP - broadcast/multicast scenarios where TCP connections aren’t practical
  • SNMP - network management traffic that needs to work even when network is stressed
  • Streaming media - losing occasional packets is better than delays from retransmission

UDP vs TCP Comparison

Aspect UDP TCP
Connection Connectionless Connection-oriented
Reliability Unreliable Reliable
Speed Fast (low overhead) Slower (high overhead)
Header Size 8 bytes 20+ bytes
Flow Control None Yes
Error Recovery None Automatic retransmission
Use Cases Real-time, broadcast File transfer, web browsing

Common UDP Port Numbers

Port Service Purpose
53 DNS Domain name resolution
67/68 DHCP IP address assignment
69 TFTP Trivial file transfer
161/162 SNMP Network management
514 Syslog System logging

Vocabulary

  • Datagram: UDP’s term for its data unit (equivalent to TCP’s segment)
  • Best-effort delivery: Network attempts to deliver data but provides no guarantees
  • Connectionless: No established session between sender and receiver
  • Stateless: No memory of previous communications or transactions

Notes

  • UDP doesn’t guarantee delivery, order, or duplicate protection - applications must handle these issues if needed
  • Checksum is optional in IPv4 but mandatory in IPv6 (helps catch transmission errors)
  • Maximum theoretical UDP datagram size is 65,507 bytes (65,535 - 20 IP header - 8 UDP header)
  • Practical MTU limits typically restrict UDP datagrams to ~1,472 bytes to avoid IP fragmentation
  • Applications using UDP often implement their own reliability mechanisms when needed (like TFTP’s acknowledgment system)
  • Firewall consideration: UDP’s stateless nature makes it harder to track connections compared to TCP
  • Perfect for multicast and broadcast traffic since TCP’s connection-oriented nature doesn’t work with one-to-many communication