Skip to content
UDP — Connectionless
step 1/5

Reading — step 1 of 5

Read

~2 min readUDP & TCP Basics

UDP: The Minimal Transport

UDP (RFC 768) is what you get when you add the bare minimum to IP to make it useful to applications: a way to address a process, and an optional integrity check. That is the whole protocol. Its header is eight bytes:

 0               15 16              31
+-----------------+-----------------+
|   Source Port   | Destination Port|
+-----------------+-----------------+
|     Length      |     Checksum    |
+-----------------+-----------------+
  • Source / Destination Port — the demultiplexing keys that route a datagram to the right process.
  • Length — the length of the UDP header plus data, in bytes. Minimum 8 (header only).
  • Checksum — covers the header, the data, and a pseudo-header borrowed from IP (source address, destination address, protocol, UDP length). The pseudo-header is never transmitted; both ends reconstruct it. It exists so a datagram delivered to the wrong host or protocol fails the check instead of being processed.

What UDP gives you, and what it refuses to

Gives you: ports, and optional integrity. That is it. It explicitly does not give you connection setup, retransmission, ordering, flow control, or congestion control. A UDP sendto puts one datagram on the wire and forgets it.

That sounds useless until you notice how many workloads want exactly that:

  • DNS — one small question, one small answer; if it is lost, just ask again.
  • Voice and video — a late packet is worse than a lost one; never wait, never resend.
  • Games — at 60 updates a second, retransmitting a stale snapshot is pointless.
  • DHCP, NTP — stateless request/reply where a connection would be pure overhead.

Modern QUIC (the transport under HTTP/3) is built on UDP — not because UDP is reliable, but because it gets out of the way, letting QUIC implement reliability, ordering, and congestion control in userspace where they can evolve without waiting for kernels.

The trap: the checksum has two sharp edges

First, a UDP checksum of all zeros on the wire means "no checksum computed." So if your computed checksum happens to come out to zero, you must transmit 0xFFFF instead (its one's-complement equal), because 0x0000 is reserved to mean "disabled." Second, the checksum covers the pseudo-header, so you cannot compute it from the UDP bytes alone — you need the IP addresses. Sum only the UDP header and data and every checksum you send will be wrong.

A stateless echo server is the whole point of UDP — there is no connection to accept, no state to keep:

python

Discussion

Ask a question, share an insight, or help someone who’s stuck.

Sign in to post a comment or reply.

Loading…