ConceptDifficulty: Beginner2 min

UDP: Send and Forget

A datagram goes out once, with no connection, no order and no promise that it arrives.

UDP sends each message as one datagram and makes no promise about it: there is no connection to set up, no acknowledgement, no retransmission and no ordering. What it adds to IP is a port number at each end, so the datagram reaches the right program, and a checksum, so a corrupted datagram is discarded rather than delivered.

The whole header is eight bytes, four fields of two bytes each.

The UDP header, eight bytes in all
FieldSizeHolds
Source port2 bytesThe sender's port, so a reply can come back
Destination port2 bytesThe receiving program's port
Length2 bytesThe header and data together, in bytes
Checksum2 bytesA check that the header and data arrived unchanged

What UDP leaves out is the point of it.

No handshake. The first datagram carries data. A DNS lookup is one datagram out and one back, so the answer arrives in a single round trip.

No retransmission. A lost datagram stays lost. If the application wants it again, the application must notice and ask.

No ordering. Datagrams can arrive in a different order from the one they were sent in, and UDP hands them over as they come.

Message boundaries are kept. A program that sends a 300-byte datagram and then a 500-byte one, and receives both, receives them as two messages of 300 and 500 bytes. TCP, by contrast, delivers one unbroken stream of bytes.

Those absences suit two kinds of program. The first sends small, independent questions where a retry is cheap: DNS, and the network time protocol. The second sends a constant flow where old data is worthless once new data exists: voice and video calls, live streams, and online games, where a late sound sample or a stale position is better skipped than waited for.

Because UDP is so thin, it is also the base for protocols that build their own rules. QUIC, the transport under HTTP/3, runs on UDP and adds its own reliability and encryption, which lets it be changed without waiting for every operating system to update.

So reach for UDP when each message stands alone, or when waiting for a lost one costs more than going without it.