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:

Get hands-on with 1200+ tech skills courses.