Deepak Choudhary

UDP Checksum calculation with an example

In this blog post, I will be explaining the calculation of the UDP checksum field with an example.

According to the RFC 768, UDP checksum field calculation includes the UDP header, Pseudo header, and the UDP Data.

UDP Header consists of sourcePort (16 bits), destinationPort (16 bits), length (16 bits), and checksum (16 bits). The sourcePort and destinationPort field values can be obtained directly. The length field is the sum of length of the UDP header and the UDP data. The checksum field is initialized to zero.

Pseudo Header consists of sourceIP (32 bits), destinationIP (32 bits), reserved (8 bits set to zero), protocol (8 bits), and length (16 bits). The sourceIP and destinationIP can be obtained directly. The protocol field is transport layer protocol value (which is 0x11 for UDP). The length field is the sum of length of the UDP header and the UDP data.

UDP Data is the data part of a UDP segment.

Now that we have the necessary information, for the ethernet frame given below, let's calculate the UDP checksum field:

f8 bc 12 86 23 bf 50 9a 4c 1e bd 18 08 00 45 00 
00 28 18 8f 40 00 40 11 8c 57 0a 72 40 b2 0a 72 
40 49 13 88 13 88 00 14 00 00 48 65 6c 6c 6f 2c 
20 77 6f 72 6c 64

From the above ethernet frame, the following fields can be deduced:

Ethernet Header:

IP Header:

UDP Header:

UDP Data:

48 65 6c 6c 6f 2c 20 77 6f 72 6c 64

Therefore, the UDP checksum segment:

13 88 13 88 00 14 00 00 0a 72 40 b2 0a 72 40 49 
00 11 00 14 48 65 6c 6c 6f 2c 20 77 6f 72 6c 64

Steps to calculate the UDP checksum:

Thus, the UDP checksum field value is 0x228B.