UDP Protocol tutorial | UDP header format and protocol functions.

UDP stands for User Datagram Protocol, and the specification is provided in RFC 768. IANA has assigned protocol number 17 to the UDP. A datagram is a basic unit in the computer network for data transfer among connected devices. It contains a protocol header and the actual information from the user. 

What is UDP?

As per the OSI model, UDP implements the transport layer protocol. When the user needs to send a message to the peer, it sends a payload and a header containing the source and destination address. Upon getting the request, UDP sets a header and sends it to the IP layer to transfer to the destination IP.

In this tutorial, we will learn the following:

  1. UDP protocol basics.
  2. UDP header.
  3. Need for UDP protocol.
  4. Example of the protocol.
  5. A comparison with other transport layer protocols.

What are the basic features of UDP?

Over a computer network or the Internet, UDP is a frequently used communication protocol. It is the simplest transport layer protocol used for data transfer. It adds a small header to a user packet and passes it to the network layer for routing on the network.

The following are the features of the UDP.

  • Connection Less:  Prior to sending any data, there is no handshake or connection setup. If the destination host is not ready to receive, an ICMP error propagates to the source from the destination, and data is dropped.
  • Not a reliable protocol: UDP does not have acknowledgment and retransmission functionalities. Once data is sent, the sender protocol clears all states and does not wait for any confirmation.
  • Do not guarantee sequence delivery to the user messages: The underlying IP network may deliver packets to the peer UDP in a sequence other than sent from the source. The UDP header does not add any sequencing information. The protocol sends the network packets to the user as they come from the underlying network layer.
  • No flow or congestion control: If the receiver is slower in processing than the sender, there is no way the sender will know about it.
  • Fast delivery: A simple protocol without too much header information and functionalities. It works in a faster way as compared to other protocols, e.g., TCP.

What are the UDP primitives?

Primitives of a protocol layer are the interfaces with its user and service providers. UDP has only two primitives, one to send user data and another to receive network data.

Explaining UDP Header format.

The header is the information that UDP adds to the payload before sending it to the destination. The receiver removes the header and sends only the payload to the user application. A Header has the following fields of 16 bits each.

UDP protocol header
  • Source Port: Port number of the sender application.
  • Destination Port: Port Number of the receiver application.
  • Length: Total length, including the header.
  • Checksum:  An optional functionality in UDP for error control.

Application Addressing Over UDP:

Similar to TCP, a user application is identified by a port number. A port number is a two bytes integer value. The application may use any unused port number to send and receive user data.

Why do we need the UDP protocol?

Till now, we know that UDP is the simplest transport layer protocol. Having no sequencing, flow control, or reliable delivery. But still, it is used widely. Why so?

The answer is the kind of applications that need a datagram protocol. These applications are used for time-critical tasks, e.g., DNS and multimedia applications have no handshake and other time-consuming functionalities.

UDP provides a rapid delivery of datagrams to the destination. For example, if we use TCP, there may be a delay in a multimedia session that is not good for the end-user experience. Here, UDP is a better choice.

Other than time-critical, the UDP adds a lesser number of header bytes than TCP does. So where we have very low space for communication, UDP is a better option, for example, TFTP.