User Datagram Protocol

UDP Definition and How It's Different Than TCP

Coworkers in conference room participating in video conference call
Thomas Barwick / Stone / Getty Images

UDP (User Datagram Protocol) was introduced in 1980 and is one of the oldest network protocols in existence. It's a simple OSI transport layer protocol for client/server network applications, is based on Internet Protocol (IP), and is the main alternative to TCP.

A brief explanation of UDP might explain that it's an unreliable protocol when compared to TCP. While that is true, since there isn't any error checking or correcting involved in data transmissions, it's also true that there are definitely applications for this protocol that TCP can't match.

UDP (sometimes referred to as UDP/IP) is often used in videoconferencing applications or computer games that are made specifically for real-time performance. To achieve higher performance, the protocol allows individual packets to be dropped (with no retries) and UDP packets to be received in a different order than they were sent, as dictated by the application.

This method of transmission, when compared to TCP, allows for less data overhead and delays. Since the packets are sent no matter what, and there isn't any error checking involved, it results in using less bandwidth.

Is UDP Better Than TCP?

The answer to this question depends on the context since UDP allows for better performance, but possibly worse quality, than TCP.

A good example of when UDP might be preferred over TCP is when it comes to an application that performs better with less latency, such as online gaming, video chatting, voice transmissions, etc.

Packets can be lost but with less overall delays to dampen quality, not much quality loss is truly perceived.

With online gaming, UDP traffic allows the game to continue even if the connection is lost momentarily, or if some of the packets are dropped for whatever reason. If error correction were involved, the connection would suffer time loss since the packets are trying to reenter where they left off to make up for the errors, but that's unnecessary in live video games.

The same is true with live streaming. However, the reason UDP is not so great when it comes to file transfers is because you do need the entire file in order use it properly. You don't, however, need every single packet of a video game or video in order to enjoy it.

Both TCP and UDP in layer 4 of the OSI model and work with services like TFTP, RTSP, and DNS.

UDP Datagrams

UDP traffic works through what's called datagrams, with every datagram consisting of a single message unit. The header details are stored in the very first eight bytes but the rest is what holds onto the actual message.

Each part of a UDP datagram header, listed here, is two bytes:

  • source port number
  • destination port number
  • datagram size
  • checksum

UDP port numbers allow different applications to maintain their own channels for data, similar to TCP. UDP port headers are two bytes long; therefore, valid UDP port numbers range from 0 to 65535.

The UDP datagram size is a count of the total number of bytes contained in header and data sections. As the header length is a fixed size, this field effectively tracks the length of the variable-sized data portion (sometimes called payload).

The size of datagrams vary depending on the operating environment, but have a maximum of 65535 bytes.

UDP checksums protect message data from tampering. The checksum value represents an encoding of the datagram data calculated first by the sender and later by the receiver. Should an individual datagram be tampered with or get corrupted during transmission, the UDP protocol detects a checksum calculation mismatch.

In UDP, checksumming is optional, as opposed to TCP where checksums are mandatory.