UDP Checksum Calculation & Why UDP?

Let's look at how the UDP checksum is calculated in-depth, why UDP would ever get used, and applications that use UDP.

UDP detects if any changes were introduced into a message while it traveled over the network. To do so, it appends a ‘checksum’ to the packet as a field that can be checked against the message itself to see if it was corrupted. It’s calculated the same way as in TCP. Here’s a refresher with some extra information:

Checksum Calculation

  1. The payload and some of the headers (including some IP headers) are all divided into 16-bit words.
  2. These words are then added together, wrapping any overflow around.
  3. Lastly, the one’s complement of the resultant sum is taken and appended to the message as the checksum.

Note: Also, note that if a message cannot be perfectly divided into 16-bit chunks, then the last word is padded to the right with zeros. This is only for checksum calculation though! The actual message does not have these zeros.

Here’s a visual of how the checksum for a datagram is calculated:

Press + to interact
Assume a message can be divided into these 3 16-bit words
Assume a message can be divided into these 3 16-bit words
1 of 22

At the receiving end, UDP sums the message in 16-bit words and adds the sum to the sent checksum. If the result is 1111111111111111, the message was not corrupted. If the result is otherwise, it was.

What if the checksum field gets corrupted?

If the checksum itself gets corrupted, UDP will assume that the message has an error.

Why UDP?

You might be wondering why would anyone use UDP when it has so many apparent drawbacks and doesn’t really do anything? Well, there are actually a number of reasons why UDP would be a good choice for certain applications.

  1. UDP can be faster. Some applications cannot tolerate the load of the retransmission mechanism of TCP, the other transport layer protocol.

  2. Reliability can be built on top of UDP. TCP ensures that every message is sent by resending it if necessary. However, this reliability can be built in the application itself.

  3. UDP gives finer control over what message is sent and when it is sent. This can allow the application developer to decide what messages are important and which do not need concrete reliability.

  4. Going on points 3 and 4, UDP allows custom protocols to be built on top of it.

    • In fact, Google’s transport layer protocol, Quick UDP Internet Connections (QUIC), pronounced quick, is an experimental transport layer network protocol built on top of UDP and designed by Google. The overall goal is to reduce latency compared to that of TCP. It’s used by most connections from the Chrome web browser to Google’s servers!
  5. With the significantly smaller header gives UDP an edge over TCP in terms of reduced transmission overhead and quicker transmission times.

Well-Known Applications That Use UDP

Xbox Live

Xbox live is built on UDP.

Press + to interact
Yes, Xbox live runs on UDP!
Yes, Xbox live runs on UDP!

Name Translation

Yes, DNS uses UDP! In the case of failed message delivery, DNS either:

  1. Resends the message.
  2. Sends the message to some other server.
  3. Gives a failure message.

Using UDP instead of TCP makes DNS and consequently, web browsing significantly faster.

Network Management

Network management and network monitoring is done using a protocol called Simple Network Management Protocol and it runs on UDP as well.

Quick Quiz!

1

An application implements its own mechanisms of checksums and retransmissions. UDP is the ideal choice of transport layer protocol for this application.

A)

True

B)

False

Question 1 of 40 attempted

Let’s look at some actual live UDP packets in the next lesson with TCPDUMP!

Get hands-on with 1400+ tech skills courses.