diagram.mmd — flowchart
UDP Packet Flow flowchart diagram

UDP (User Datagram Protocol) is a connectionless transport protocol that sends discrete packets — called datagrams — with no setup handshake, no delivery guarantee, and no ordering enforcement.

Where TCP prioritizes reliability, UDP prioritizes speed. The trade-off is appropriate for latency-sensitive applications where occasional packet loss is preferable to retransmission delays: live video/audio streaming, online gaming, DNS queries, VoIP, and network monitoring.

No Connection Setup: UDP requires no handshake. The application hands a datagram to the socket, and the kernel immediately encapsulates it in a UDP header (source port, destination port, length, checksum) and passes it to the IP layer. Total overhead is 8 bytes per datagram.

IP Encapsulation: The IP layer adds its own header (source IP, destination IP, TTL, protocol=17 for UDP) and routes the packet toward the destination. Each datagram is routed independently — successive datagrams between the same endpoints may take different paths.

No Acknowledgment: The sender gets no confirmation of delivery. If a datagram is lost due to congestion, a routing failure, or buffer overflow, it simply disappears. The application is responsible for handling retransmission if needed.

No Ordering: Datagrams may arrive out of order. A datagram sent later may arrive before one sent earlier. Again, the application layer must reorder if required.

Checksum: UDP includes an optional (IPv4) or mandatory (IPv6) checksum covering the header and data. This detects corruption but does not trigger retransmission.

These properties make UDP the foundation for modern protocols like QUIC, which builds its own reliability, ordering, and congestion control on top of UDP to gain the deployment flexibility of UDP (traverses NAT, no kernel state) while achieving TCP-like guarantees at the application layer.

Free online editor
Edit this diagram in Graphlet
Fork, modify, and export to SVG or PNG. No sign-up required.
Open in Graphlet →

Frequently asked questions

UDP (User Datagram Protocol) is a connectionless transport protocol that sends discrete datagrams with no setup handshake, no delivery guarantee, and no ordering enforcement. Use UDP when the overhead of TCP's reliability mechanisms (connection setup, retransmission, ordering) would introduce more latency than the occasional lost packet — DNS queries, live video/audio streaming, online gaming, VoIP, and network monitoring are all good fits.
TCP requires a three-way handshake before data flows, guarantees ordered delivery, retransmits lost segments, and provides flow and congestion control. UDP requires no setup, sends datagrams immediately, provides no delivery or ordering guarantees, and has no built-in retransmission. UDP's header is 8 bytes; TCP's is 20+ bytes. UDP is faster for short exchanges where reliability is handled at the application layer or not needed.
The sender receives no notification that a packet was lost — it simply disappears. Any packet sent later may arrive before earlier packets without warning. The application layer is responsible for implementing retransmission, duplicate detection, and reordering if required. DNS, for example, retries after a timeout; video streaming typically interpolates or drops missing frames rather than retransmitting.
QUIC uses UDP because UDP bypasses the kernel's built-in TCP implementation, allowing QUIC to evolve rapidly via application updates rather than OS kernel upgrades. Running on UDP also means QUIC can implement its own connection model (identified by Connection ID rather than IP 4-tuple), enabling connection migration when IP addresses change — impossible with TCP.
mermaid
flowchart LR A([Application]) --> B[Create UDP socket\nsocket SOCK_DGRAM] B --> C[sendto: dest IP + port\n+ datagram payload] C --> D[OS: Add UDP header\nSrc port, Dst port,\nLength, Checksum] D --> E[OS: Add IP header\nSrc IP, Dst IP,\nTTL, Protocol=17] E --> F{NAT Device?} F -->|Yes| G[Rewrite src IP:port\nRecord mapping] G --> H[Network Transit\nRoute via IP] F -->|No| H H --> I{Packet Lost?} I -->|Yes| J([Datagram dropped\nNo retransmission]) I -->|No| K[Destination receives\nIP+UDP packet] K --> L[Strip IP header\nVerify checksum] L --> M[Deliver to app\nvia dest port] M --> N([Application receives\ndatagram — no ACK sent])
Copied to clipboard