UDP Protocol tutorial | UDP header and functions

The UDP full form is the user datagram protocol. A datagram is a basic unit over the network for data transfer, having a header, and the actual payload from the user.  As per the OSI model, it is an example of a layer four protocol. When a UDP user needs to send a message to the peer,  it sends a payload along with source and destination information.  Upon getting the request, UDP sets a header and sends it to the IP layer to transfer to the destination IP. The protocol specification is in RFC 768.

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. Comparison with other protocols of the transport layer.

UDP Protocol basics:

UDP is one of the communication protocols over a computer network or the internet.  This is the simplest protocol for data transfer. Just adds a header and sends it to the network layer for further transfer. The following are the basic functionalities.

  • Connection Less:  Prior to sending any data, there is no handshake or connection setup.  If the destination host is not ready to receive, there is an ICMP error propagating 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 destination UDP in a sequence other than sent from the source.  UDP header does not add any sequencing information. The protocol sends the network packets to the user as they come from IP.
  • No flow or congestion control: If the receiver is slower in processing than the sender, there is no way the sender will know.
  • Fast delivery:  Being a simple protocol, without too much header information and functionalities. It works in a faster way as compared to other protocols e.g TCP.

UDP primitives:

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

UDP Header:

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 of UDP is identified by a port number. A port number is an integer value.  The application may use any free port number to send or receive user data.

Why do we need the UDP protocol?

Till now we know that UDP is the most simples transport protocol. Have no sequencing, flow control, and reliable delivery. But still, it is used widely why so?  The answer is the kind of applications that need a datagram protocol. The applications are time-critical applications e.g DNS and multimedia applications.  As no handshake and other time-consuming functionalities. UDP provides a rapid delivery of datagrams to the destination.  For example, if we use TCP then 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.