Labs ICT
โญ Pro Login

UDP (User Datagram Protocol)

Fast, lightweight, and doesn't care if you miss a packet.

The Fast and Furious Protocol

UDP (User Datagram Protocol) is the lightweight alternative to TCP. It sends data without establishing a connection, without acknowledgments, without ordering, and without guarantees. It's the "fire and forget" protocol.

If TCP is certified mail with tracking and signature confirmation, UDP is tossing a letter over a fence โ€” it might arrive, it might not, and you won't know either way.

How UDP Works

UDP is beautifully simple. The application writes data, UDP wraps it in a header with source and destination ports and a checksum, and sends it. That's it. No handshake, no ACKs, no retransmission.


  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
  โ”‚ Src Port   โ”‚ Dst Port   โ”‚  Length    โ”‚  Checksum  โ”‚
  โ”‚ (16 bits)  โ”‚ (16 bits)  โ”‚ (16 bits)  โ”‚ (16 bits)  โ”‚
  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                    โ”‚
                    โ–ผ
              โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
              โ”‚   Data   โ”‚
              โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

The UDP header is just 8 bytes โ€” compared to TCP's 20-60 bytes. Less overhead means faster transmission.

When to Use UDP

UDP is perfect when speed matters more than reliability:

  • Video streaming โ€” If a frame is lost, it's better to skip it and show the next one than to wait for a retransmission. The viewer might see a brief glitch, but the video keeps playing.
  • Online gaming โ€” Game updates need to arrive fast. A 50ms delay from TCP retransmission could mean the difference between hitting and missing a target. If a packet is lost, the next one will have updated data anyway.
  • DNS queries โ€” A DNS lookup is a single request and response. There's no stream to order โ€” you either get the answer or you don't. UDP is perfect for this.
  • Voice over IP (VoIP) โ€” Real-time voice can't wait for retransmissions. Dropped packets result in brief audio gaps, which is acceptable compared to the delays TCP would introduce.
  • Broadcast/Multicast โ€” UDP supports broadcast and multicast; TCP doesn't.

What UDP Doesn't Do

  • No connection setup โ€” No handshake. Data is sent immediately.
  • No reliability โ€” Lost packets are gone forever. The application must handle this if it matters.
  • No ordering โ€” Packets might arrive out of order. The application must sort them if needed.
  • No flow control โ€” The sender can blast data as fast as it wants, potentially overwhelming the receiver.
  • No congestion control โ€” UDP doesn't care if the network is congested. It sends at full speed regardless.

This isn't a flaw โ€” it's a design choice. UDP gives applications control over what reliability mechanisms they need, rather than imposing a one-size-fits-all solution.

Application-Level Reliability

Many applications that use UDP add their own reliability mechanisms. For example, modern video streaming protocols (like QUIC, which underlies HTTP/3) build reliability on top of UDP while maintaining its speed advantages.

The philosophy is: let the application decide what reliability means for its specific use case, rather than forcing TCP's heavy guarantees on everything.

๐Ÿงช Quick Quiz

When should you use UDP instead of TCP?