4.3.18 · D1Computer Networks

Foundations — UDP — header, use cases, checksum

1,871 words9 min readBack to topic

Before you read the parent note on UDP, you need to be fluent in a handful of tiny ideas. Below, each one is built from nothing — plain words first, then a picture, then why UDP needs it. Read them in order; each leans on the one before.


1. A bit — the smallest unit of everything

The picture: imagine a row of light switches. Each switch is either OFF () or ON (). A bit is one switch.

Why UDP needs it: every field in the UDP header — every port, the length, the checksum — is ultimately a row of these switches. When the parent note says "a bit flipped in transit," it means noise on the wire flicked one switch the wrong way. The checksum's entire job is to notice that flick.

Figure — UDP — header, use cases, checksum

2. A byte and a 16-bit word — grouping switches

The picture: if a bit is one switch, a byte is a strip of 8 switches, and a 16-bit word is a strip of 16 switches. Think of a ruler broken into segments.

Why UDP needs it: the header says each field is "16 bits." That means each field is exactly one 16-bit word — one strip of 16 switches. The checksum also chews the data 16 bits at a time. So "16-bit word" is the natural unit for the whole topic.

Recall Why

and not ? Each new switch doubles the possibilities (every old pattern can now have the new switch OFF or ON). Doubling times is . Why is the largest value and not ? ::: Because we count from . The values are , which is different numbers plus zero = patterns.


3. Hexadecimal — a shorthand for bits

The picture: take a 16-bit strip and cut it into four groups of 4 bits. Each group of 4 switches has patterns — exactly one hex digit. So one 16-bit word = four hex digits.

Why UDP needs it: writing 16 zeros and ones is exhausting and error-prone. The parent's checksum example uses , — that's just four-switch groups written compactly. You must be able to read hex to follow the checksum math.

Figure — UDP — header, use cases, checksum

4. A port number — "which program?"

The picture: a machine is an apartment building; its IP address is the street address that gets a letter to the building. But many people (programs) live inside. The port number is the apartment number that tells the mail carrier which door to slide the letter under.

Why UDP needs it: IP alone delivers only to the building (the machine). UDP's whole reason to exist starts with adding source port + destination port so the right program gets the data. The parent note derives the header from exactly this need. See Transport layer — ports and multiplexing for how one machine juggles many ports at once.


5. IP, datagram, and the layer below

The picture: IP is the postal road network that gets an envelope from city to city. A datagram is one sealed envelope — complete in itself, with no assumption that other envelopes come before or after it.

Why UDP needs it: UDP is a thin wrapper on top of IP. It does not re-do IP's job of routing across machines; it just adds ports and a checksum. The word "datagram" in "User Datagram Protocol" tells you UDP keeps message boundaries — one send, one whole envelope. See IP — datagrams and addressing.


6. Binary addition and the carry

The picture: think of an odometer or a stack of dials. When a dial rolls past its max, it flips back and nudges the dial to its left forward by one. That nudge is the carry.

Why UDP needs it: the checksum adds many 16-bit words. Two 16-bit numbers can add up to something needing a 17th bit — that extra top bit is an overflow carry. What UDP does with that carry (recycle it, not throw it away) is the heart of the checksum. Next section.


7. One's-complement addition — the checksum's special adder

The picture: ordinary addition lets the carry escape off the top and vanish. One's-complement addition catches that escaping carry and feeds it back in at the bottom — like a circular track where whatever falls off the top re-enters at the start. Nothing is lost.

Figure — UDP — header, use cases, checksum

Why UDP needs it:

  • Carry-wrap keeps the running sum inside 16 bits (the checksum field is only 16 bits) without discarding information — the overflow is recycled, not dropped.
  • Complementing at the end is what lets the receiver just add everything including the checksum and expect all-ones (), because of the all-ones fact. That is precisely the parent's receiver-check trick.

8. "Checksum" as a concept — an alarm bell, not a lock

The picture: you count the letters in a note and scribble that count at the bottom. Your friend re-counts; a mismatch means the note got smudged in transit. It's a smoke detector: it rings, it does not put out the fire.

Why UDP needs it: IP checksums only its own header, never your data. UDP adds this alarm bell so at least corruption of the payload can be noticed and the datagram dropped. The nuance — two errors can cancel, so it can be fooled — is exactly why the parent warns against treating it as strong integrity.


How these foundations feed the topic

Bit - one switch

Byte and 16-bit word

Hexadecimal shorthand

Port number - 16 bits

Binary addition and carry

Ones complement addition

Checksum concept

IP and datagram

UDP wrapper

UDP header and use cases

Read it top to bottom: switches build words, words build hex and ports, addition builds the one's-complement adder, that builds the checksum — and ports + checksum + IP together are UDP.


Equipment checklist

Cover the answers and test yourself before moving to the parent note.

A bit is
one switch — a single or .
A 16-bit word holds how many distinct values?
, i.e. to .
One hex digit encodes how many bits?
exactly 4 bits (a group of 4 switches).
Convert intuition: the leading and mean...
the high byte is , i.e. bit pattern .
A port number answers which question?
which program on the machine gets this message (the apartment number).
IP alone delivers to a
machine (the building / IP address), not a specific program.
An overflow carry in one's-complement addition is
added back into the low 16 bits (wrapped around), never discarded.
for 16-bit numbers equals
all-ones, .
A checksum's job is to
detect corruption, not repair it and not secure it.
Why does UDP add a checksum when IP already has one?
IP only checksums its own header, not your data payload.