Skip to content

UDP Protocol - lightweight and fast, but no guarantees

User Datagram Protocol (UDP) is a transport layer protocol. It is characterized by simplicity, low overhead, and a lack of mechanisms guaranteeing data delivery.

Key features

UDP is a connectionless protocol - it does not establish a session between sender and receiver. Each packet (datagram) is sent independently, which means:

  • no acknowledgments (ACK),
  • no retransmission of lost packets,
  • no congestion control,
  • no ordering control,
  • no connection negotiation - data is simply sent.

Thanks to this, UDP is very fast and ideal in situations where timing is more important than reliability, e.g. video/audio streaming, VoIP, DNS, or multiplayer mode in games (in case you happen to be programming a client/server game).

UDP packet structure

Field Size (bits) Description
Source port 16 Sending port number (optional)
Destination port 16 Receiver port number
Length 16 Length of the entire UDP segment (header + data)
Checksum 16 Error control (optional)

Note

Slightly smaller than in TCP, right? :)

Data in UDP

Data in UDP is sent as a byte stream. The protocol does not interpret its contents, this is the application's job. This allows you to send various types of data, e.g. text, images, or audio. The maximum reserved size for data is 65,507 bytes (65535 - 8 bytes of UDP header).

How does it work?

Below is the data flow in UDP. There is no acknowledgment or retransmission, so packets may arrive out of order or not at all.

sequenceDiagram
    participant Application
    participant UDP
    participant Network
    participant Receiver

    Application->>UDP: data to send
    UDP->>Network: UDP datagram
    Network-->>Receiver: UDP datagram
    Note over Network,Receiver: no acknowledgment<br>no retransmission

Can you number packets in UDP?

UDP itself does not have a field for packet numbering - it does not know which packet was first or last. But that does not mean applications cannot handle this themselves.

Example: TFTP

Trivial File Transfer Protocol (TFTP) works over UDP and numbers packets itself at the application layer. Each data block has a block number, which the receiver must acknowledge. If there is no response, the sender retransmits the block.

Other examples of applications that implement their own packet numbering logic:

  • RTP (Real-time Transport Protocol) - uses sequence numbers to play audio or video in the correct order
  • QUIC - built on top of UDP, implements its own guaranteed transport and encryption logic

When to use UDP?

UDP works great when:

  • latency is more important than reliability (VoIP, streaming, DNS),
  • you can afford to lose individual packets,
  • the application can manage retransmission itself (e.g. TFTP),
  • IoT devices where you operate with minimal resources

How does it work in Linux?

In Linux, UDP is handled by the kernel, which implements the entire protocol. User processes use the socket interface to send and receive data via UDP, but do not deal with the protocol logic itself - the operating system kernel does that, just like with TCP.

Capturing and analyzing UDP traffic

You can use the tcpdump tool to capture and analyze UDP traffic. Example command:

tcpdump -i eth0 udp port 53

Summary

UDP is a fast and lightweight protocol without delivery guarantees, operating on a send and forget principle. The lack of built-in reliable transmission logic does not mean it cannot be achieved - many applications handle this themselves by adding their own control layer.

If you need maximum speed and your application can handle possible losses, UDP will be a great choice.