UDP: What is the User Datagram Protocol?
The communication of systems in local home and corporate networks as well as public networks such as the internet is based by default on the internet protocol family. The most well-known component of this protocol stack is undoubtedly the Internet Protocol (IP), which is not only responsible for addressing and fragmenting data packets, but also defines how information about source and destination is described. However, the transmission of data is usually handled by the connection-orientated Transmission Control Protocol (TCP), which is why networks are often referred to as TCP/IP networks. Because TCP provides security but also delays transmission, David Patrick Reed published his User Datagram Protocol (UDP) concept in 1980 as a simpler and faster alternative to the standard protocol.
What is UDP (User Datagram Protocol)?
The User Datagram Protocol, or UDP for short, is a protocol that allows datagrams to be sent without connection in IP-based networks. To achieve the desired services on the target hosts, it uses ports that are listed as one of the core components in the UDP header. Like many other network protocols, UDP belongs to the internet protocol family, where it is classified as a mediator between the network layer and the application layer at the transport level.
UDP is a direct alternative to the more common TCP, although the two protocols differ by one point: While transmission via TCP takes place only after the obligatory three-way handshake (mutual authentication between sender and addressee including connection setup), UDP forgoes this procedure in order to keep the transmission time as short as possible.
By using the User Datagram Protocol, an application can send information very quickly, since neither a connection to the addressee has to be established nor do you have to wait for an answer. However, there is no guarantee that packets will arrive complete and in the same order in which they were sent. In addition, the protocol does not provide its own protection against manipulation or access by third parties. However, faulty packets can be detected by an optional usable checksum (mandatory in combination with IPv6).
What is UDP? UDP (User Datagram Protocol) is a connectionless protocol of the internet protocol family that operates at the transport layer and was specified in 1980 in RFC (Request for Comments) 768. As a lean and almost delay-free alternative to TCP, UDP is used for the fast transmission of data packets in IP networks. Typical fields of application for UDP are DNS queries, VPN connections, and audio/video streaming.
The features of UDP at a glance
To understand how packet transmission works with the protocol in detail, it is useful to take a closer look at the properties of the User Datagram Protocol.
- UDP is connectionless: Data transport via UDP is characterised by the fact that it takes place without an existing connection between addressee and recipient. The respective packets are then sent to the preferred IP address, specifying the target port, without the computer behind them having to respond. However, if packets are also to be returned to the recipient, the UDP header can optionally also contain the source port.
- UDP uses ports: Like TCP, UDP uses ports so that the packets are transferred to the correct subsequent protocols or the desired applications on the target system. The ports are defined by numbers according to the proven pattern, with numbers between 0 and 1023 assigned to fixed services.
- UDP enables fast, delay-free communication: The transport protocol is suitable for fast data transmission due to the lack of connection setup. This also results from the fact that the loss of individual packets only affects the quality of the transmission. With TCP connections, on the other hand, lost packets are automatically re-requested, causing the entire transmission process to come to a standstill.
- UDP does not guarantee the security and integrity of the data: The absence of mutual authentication between addressee and recipient ensures the excellent transmission speed of UDP – however, the protocol can neither guarantee the completeness nor the security of the data packets. The correct sequence of the sent packets is also not guaranteed. For this reason, the services that use UDP must provide their own measures for correction or protection.
The most important feature of the User Datagram Protocol is its ability to transport data packets without an existing connection. The resulting speed advantages for the transmission are associated with a high susceptibility to manipulation, uncorrected packet loss, and a partially arbitrary sorting of the packets. For this reason, UDP applications must be able to work well with missing and unsorted data packets and/or have their own correction and security mechanisms.
How is the UDP header structured?
As is typical for protocols, UDP packets consist of a header and the actual user data. The UDP header contains all the information required for data transmission using the transport protocol, and makes a UDP packet identifiable as such. Divided into two 32-bit blocks with four different data fields, the structure is as follows:
Bits 0-15 | Bits 16-31 | |
0 | Source port | Target port |
32 | Length | Checksum |
The first 16 bits of the header area reveal the source port via which the respective data packet is sent. The receiver needs this information to be able to respond to the packet. Since UDP is connectionless and there is no exchange between addressee and receiver, this field is optional. Therefore, the value "0" is usually set here.
In the next field, the target port and thus the service to be accessed is specified. In contrast to the source port, this information is mandatory, otherwise the datagram cannot be assigned correctly.
The following principle applies to the port fields: If it is a client-side application, the assigned port number is likely to be volatile. If the port is assigned to a server process, the port number is normally one of the "known ports" (standardised ports).
The length field defines the length of the datagram. This consists of the length of the header (8 bytes) and the size of the user data (theoretical maximum: 65,535 bytes). When using IPv4, the actual limit for the user data is 65,507 bytes – after deducting IP and UDP headers. In IPv6, packets (so-called jumbograms) that exceed the maximum are also possible. According to RFC 2675, the value of the length field is set to "0" in such a case.
The UDP header is terminated by the checksum, which is used for error detection during transmission. In this way, any manipulations of the transmitted data can be detected – however, corresponding packets are discarded without a new request. To generate the sum, parts of the
- UDP header,
- the user data,
- as well as the so-called pseudo-header (contains IP header information)
are included.
The checksum is optional in IPv4, but is used by most applications by default. If you omit it, this field will also take the value "0." If UDP is used in combination with IPv6, the checksum is mandatory.
Which applications use UDP?
The User Datagram Protocol has a minimalistic structure and missing mechanisms in order to guarantee a complete, successful transmission, but cannot be used as a universal transport protocol. Rather, it was designed from the outset for applications that do not (yet) require a reliable transmission service. The field of application of UDP is consequently limited, but nevertheless underlines the enormous value of the protocol, as the following application classes for UDP prove:
- "Best-effort delivery" applications: The classic deployment scenario for UDP is applications that are based on "data delivery to the best of our ability." Such programs, which use the User Datagram Protocol as a "best effort" service, transmit information unreliably because they are used to repeating this information. Examples are applications that transmit measured values or repeatedly execute the same work orders.
- Lightweight applications: The low transport protocol overload provides optimal support for applications that are very simple in design. In combination with eliminating the need to establish a connection, these programs benefit from particularly high performance when processing and forwarding data packets in networks.
- Applications with their own mechanisms for reliable transmission: UDP can also be interesting for applications that are actually dependent on reliable information exchange, but should have their own mechanisms for answering packets. The advantage of services like these is that they are not bound to fixed patterns in order to guarantee the completeness and correctness of the data packets sent. You can decide for yourself how and when to respond to incorrect or unsorted information.
- Multicast applications: While reliable transport protocols such as TCP are limited to the use of end-to-end communication, UDP also supports IP multicast connections. If an application is to be able to send IP packets efficiently and quickly to many recipients at the same time, UDP creates a suitable basis.
- Real-time applications: UDP is also suitable as a transport protocol for services that work with real-time requirements – such as audio or video transmissions. They must be able to largely control the transmission, reception, and reproduction of data streams themselves, which is easily possible with connectionless UDP transmission.
Real-time applications now mainly use the Real-time Transport Protocol (RTP), which is based on UDP and, unlike the basic protocol, can also detect the loss of packets. The latest specification of RTP can be found in RFC 3550.