User Datagram Protocol basics

User Datagram Protocol is an Internet protocol used to transfer user data between two points without requiring a connection. This makes it very lightweight. It works on the transport layer like TCP, but is much simpler. Unlike TCP, there is no guarantee that the data packet has reached the recipient because no acknowledgements are used. This is a major drawback compared to TCP, but the upside is that the overall amount of data is smaller, so transmission is faster. The UDP message header is 8 bytes compared to TCP’s 20 bytes. This makes it a good solution for situations where low overhead is critical. UDP can be used to send data to multiple devices on a network simultaneously. Typical areas of implementation are applications such as video streaming, online gaming, Voice over IP (VoIP). In general, where speed and low latency are more important than reliability.

Datagram structure

UDP packets are called „datagrams” and are consist of two parts: an 8-byte header and a variable-length data field (up to 65507 for IPv4)

The header is divided into 4 parts:

FieldSize in bytesDescription
Source Port2Identifies the sender’s port number (it is optional).
Destination Port2Identifies the receiver’s port number.
Length2Specifies the total length of the UDP datagram (header + data).
Checksum2Used for error-checking of the header and data (optional in IPv4).

Here is an example of simple UDP datagram:

0x1F90 0x1F90 0x0024 0x1234 ucdev_blog
  • First part 0x1F90 (8080 in decimal) is source port
  • Second part is the same: 0x1F90 (8080 in decimal) and it’s destination port
  • Third part is length: 0x0024 bytes (36 in decimal, meaning 8-byte header + 28 bytes of data)
  • Checksum is 0x1234
  • Last part is text: „ucdev_blog”

Compare to TCP

FeatureUDPTCP
ConnectionConnectionlessConnection-oriented
ReliabilityUnreliable, no guarantee of deliveryReliable, guarantees delivery and order
OverheadLow (8-byte header)Higher (20-byte header)
Flow ControlNoYes
Typical UsesStreaming, VoIP, gaming, DNSFile transfer, emails, web browsing

Summary

The UDP datagram is a simple structure, designed to deliver data quickly with minimal overhead. Because it has no fields for connection management, ordering, or reliability, it’s efficient but suited for applications that can tolerate occasional data loss, like streaming or gaming.

Hello 👋 Nice to meet you.

Sign up here if you would like to be notified when new content is added to the blog.

We will not spam you. You will only receive important information, such as changes to the blog or new content.

Dodaj komentarz