The User Datagram Protocol

This lesson gives an introduction to one of the protocols at the heart of the transport layer: UDP!

What is UDP?

UDP, or User Datagram Protocol, is a transport layer protocol that works over the network layer’s famous Internet protocol (which we’ll look at in-depth in the next chapter). RFC 768 is the official RFC for UDP.

How It Works

UDP does not involve any initial handshaking like TCP does, and is hence called a connectionless protocol. This means that there are no established ‘connections’ between hosts.

UDP prepends the source and destination ports to messages from the application layer and hands them off to the network layer. The Internet Protocol of the network layer is a best-effort attempt to deliver the message. This means that the message-

  1. May or may not get delivered.
  2. May get delivered with changes in it.
  3. May get delivered out of order.

UDP only adds the absolute bare minimum functionality over the network layer. So it…

  • Does not ensure that messages get sent.
  • It does check, however, if a message got ‘corrupted’ yet does not take any measures to correct the errors by default.

Structure of A UDP Datagram

Header

UDP prepends four 2-byte header fields to the data it receives from the application layer. So in total, a UDP header is 8 bytes long. The fields are:

  1. Source port number
  2. Destination port number
  3. Length of the datagram (header and data in bytes)
  4. Checksum to detect if errors have been introduced into the message. We’ll study this in detail in the next lesson!

Data

Other than the headers, a UDP datagram contains a body of data which can be up to 65,528 bytes long. Since the maximum possible length of a UDP datagram is 216=2^{16} = 65,536 bytes which includes the 88-byte header, we are left with 65,528 bytes available. The nature of the data depends on the overlying application. So if the application is querying a DNS server, it would contain bytes of a zone file.

Here’s what a UDP message looks like:

Get hands-on with 1200+ tech skills courses.