← All chapters
Chapter 14· 6 min read · illustrated

Anatomy of a UDP Datagram

The whole UDP header is just four fields and eight bytes

UDP’s simplicity shows in its header — it has only four fields, totalling 8 bytes. This short chapter labels each one so you know exactly what UDP adds to your data.

01

The datagram = header + data

A UDP datagram is two parts: an 8-byte header followed by your data (the payload). Everything UDP does is captured in those 8 header bytes — four fields of 2 bytes each.

Tap to enlarge
02

Field 1 — Source Port

Source Port (2 bytes) identifies the sending application, so replies can find their way back to the right process. It is optional in UDP and may be 0 if no reply is expected.

Tap to enlarge
03

Field 2 — Destination Port

Destination Port (2 bytes) says which application on the receiving machine should get the datagram — for example, port 53 for DNS. This is how one IP can run many services at once.

Tap to enlarge
04

Field 3 — Length

Length (2 bytes) is the size of the entire datagram — header plus data — in bytes. The minimum is 8 (a header with no data).

Tap to enlarge
05

Field 4 — Checksum

Checksum (2 bytes) is an error-detection code covering the header, data, and a small pseudo-header of IP info. It lets the receiver detect corruption in transit. It is optional in IPv4 (0 = unused) but mandatory in IPv6.

Tap to enlarge
06

Eight bytes, that’s it

Add it up: Source Port + Destination Port + Length + Checksum, each 2 bytes, equals an 8-byte header. That tiny, fixed header is exactly why UDP is so lightweight and fast.

Tap to enlarge