4.3.18 · D3Computer Networks

Worked examples — UDP — header, use cases, checksum

3,685 words17 min readBack to topic

This page drills the 4.3.18 UDP — header, use cases, checksum (index 4.3.18) into the ground. We will compute checksums by hand, hit every overflow and edge case, and prove each answer. If you have not yet seen One's complement arithmetic, read the preliminary theory and the first two examples slowly — they build it from zero.


Preliminary theory — three tools before any arithmetic

Before we compute anything, we fix the exact notation and the exact algorithm. Every example below leans on these three tools, so nothing appears unexplained.

Read the two figures now — they carry this algorithm visually.

Figure — UDP — header, use cases, checksum
Figure 1 — sums live in 0..65535; anything spilling into the yellow strip wraps back around (green arrow).

Figure — UDP — header, use cases, checksum
Figure 2 — add, spill?, fold the whole carry, repeat, then flip. The green loop-back handles cascades.


The scenario matrix

Every worked example below is tagged with the cell it fills.

Cell Case class What makes it special
C1 No overflow Words add up small; carry never leaves 16 bits.
C2 Single wrap-around Sum crosses 0xFFFF once; recycle one carry.
C3 Cascading wrap Folding the wrapped carry causes another carry.
C4 Genuine-zero result Computed sum is all-ones → checksum would be 0x0000 → must send 0xFFFF.
C5 Disabled checksum Sender transmits literal 0x0000 (IPv4 opt-out).
C6 Pseudo-header included Source/dest IP folded in; catches misdelivery.
C7 Error slips through Two compensating bit flips pass the check.
C8 Length + odd payload Compute Length; pad a final odd byte into a word.
C9 Word-problem (DNS) Real latency comparison: why UDP not TCP.
C10 Exam twist Reconstruct a missing field from the given checksum.

The number 16 above means the field is 16 bits wide = 4 hex digits = values 0x0000..0xFFFF = 0..65535. Whenever a sum climbs above 0xFFFF, it no longer fits and the wrap-around (Figure 1) fires.













Recall Quick self-test across the matrix

Which cell forces you to transmit 0xFFFF even though your math produced zero? ::: C4 — genuine-zero sum, because 0x0000 is reserved for "disabled." Why does the pseudo-header include the destination IP? ::: C6 — so a datagram misdelivered to the wrong machine fails the checksum. Give an error the checksum cannot catch. ::: C7 — two compensating flips (+1 and −1) that leave the total unchanged. Smallest legal UDP Length value? ::: C8 — 8 (header only, empty payload); anything below 8 is malformed. How is a trailing odd byte handled in the checksum? ::: C8 — pad it on the right with a virtual 0x00 to form a full 16-bit word; the pad is not transmitted and Length still reports the true byte count. What does the overline mean? ::: Flip every one of the 16 bits — the one's complement of .


Related depth: One's complement arithmetic · IP — datagrams and addressing · Transport layer — ports and multiplexing · 4.3.18 UDP — header, use cases, checksum (Hinglish)