What is UDP (User Datagram Protocol)?
A connectionless transport-layer protocol. Its header is 8 bytes and holds only port numbers, a length and a checksum. It has no connection setup, no acknowledgments or retransmission and no ordering, so it adds little delay. It is used for DNS queries, voice and video calls, online games, DHCP and QUIC, among others.
Japanese name: UDP
UDP (User Datagram Protocol) appears in 4 practice questions across 2 topics, including Computer Networking Basics, Web Technology Basics.
Field: Computer Networking Basics
Header and datagrams
The UDP header consists of four 16-bit fields, the source port, destination port, length and checksum, for 8 bytes in total. Each block of data the application sends becomes one datagram, and the receiver gets it with the same boundaries, unlike TCP's byte stream. The checksum is optional over IPv4 but mandatory over IPv6. Large datagrams are fragmented at the IP level and are more easily lost, so applications normally keep them small enough to fit within the MTU.
When UDP is the right choice
In calls and live streaming, data that arrives late is useless, and waiting for retransmissions makes sound and video stutter. For exchanges made of a single question and answer, such as DNS queries, skipping connection setup cuts the waiting time. UDP can also be used for one-to-many broadcast and multicast, which is why DHCP, used by devices that do not yet have an IP address, runs over UDP. Applications that need reliability build retransmission and ordering on top of UDP themselves, as QUIC does.
Things to watch out for
UDP datagrams can be lost, duplicated or reordered, so the application has to cope, for example by numbering its data. UDP itself has no congestion control, so an application sending a lot of data must pace itself. NAT mappings disappear after a period without traffic, so applications sometimes send small keepalive packets to hold them open. Because there is no handshake and the source address is easy to forge, UDP services such as DNS that return large answers to small queries are abused in reflection and amplification DDoS attacks.
FAQ
Why use UDP if it is unreliable?
It does not wait for connection setup or retransmissions, so it adds little delay, and its header is small. That suits calls and games, where low delay matters more than a little missing data, and DNS queries, which finish in one round trip. When reliability is needed, protocols such as QUIC implement retransmission on top of UDP.
Does UDP data arrive in the order it was sent?
That is not guaranteed. Datagrams may be reordered, for example by taking different paths, and may also be lost or duplicated. If order matters, the application numbers its data and reorders it.