UDP
User Datagram Protocol
In short
UDP is a lightweight internet protocol that sends small, independent messages called datagrams without a connection, favoring speed over guaranteed delivery.
What is UDP?
UDP, the User Datagram Protocol, is a simple transport protocol that sends data as independent messages called datagrams. It does not set up a connection first, and it does not confirm that a message arrived, resend lost messages, or put them back in order. Like TCP, it runs on top of IP and uses port numbers to deliver each datagram to the right program.
Because UDP skips handshakes, acknowledgments, and retransmissions, it has very little overhead and low latency. Each datagram carries a small header with the source port, destination port, length, and a checksum used to detect corrupted data. If an application needs reliability, it must add its own rules on top, which is exactly what newer protocols such as QUIC do.
An everyday analogy is sending postcards: each one travels on its own, might arrive out of order, and occasionally gets lost, but you don't wait for a reply before sending the next. UDP is used where fresh data matters more than perfect data, such as live voice and video calls, online multiplayer games, DNS lookups, and HTTP/3, which runs over QUIC.
A common confusion is thinking UDP is simply a worse TCP. It is a different trade-off: in a video call, a late packet is useless, so waiting for a retransmission as TCP does would cause more stutter than just skipping it. Because it is connectionless, UDP also supports sending one message to many receivers at once through broadcast and multicast, which TCP cannot do.
At a glance
Key takeaways
- UDP is connectionless: there is no handshake before data is sent.
- It does not guarantee delivery or order, and it does not prevent duplicates.
- Low overhead makes it fast and well suited to real-time applications.
- DNS, voice and video calls, online games, and QUIC (used by HTTP/3) rely on UDP.
- Applications that need reliability over UDP must implement it themselves.
Example
import socket
# Create a UDP socket (SOCK_DGRAM means datagrams)
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
# Send a message with no connection or handshake
sock.sendto(b"player:42 x=10 y=20", ("127.0.0.1", 9999))
# Wait up to 1 second for a reply; it may never come
sock.settimeout(1.0)
try:
data, sender = sock.recvfrom(1024)
print("Reply from", sender, data)
except TimeoutError:
print("No reply: UDP does not guarantee delivery")Readers ask
Why would anyone use UDP if it is unreliable?
Because it is faster and simpler. In real-time uses like video calls or games, getting new data quickly matters more than recovering old data, and applications can add only the reliability they actually need.
Does DNS use UDP or TCP?
Most DNS queries use UDP on port 53 because they are small and need quick answers. DNS falls back to TCP for large responses and for transfers between DNS servers, and encrypted variants such as DNS over HTTPS use TCP or QUIC.
Is UDP faster than TCP?
Usually, yes, because it skips the handshake, acknowledgments, and retransmissions. The real difference depends on the network, and on an unreliable network an application may still need to add its own recovery logic.
Often compared
See also
- TCPNetworking, p. 30TCP is a core internet protocol that delivers data between two programs reliably and in order, by opening a connection and resending anything that gets lost.
- PacketNetworking, p. 20A packet is a small, formatted unit of data sent across a network, made of a header with addressing information and a payload that carries the actual data.
- PortNetworking, p. 22A port is a number from 0 to 65535 that identifies a specific program or service on a device, so traffic reaching an IP address gets to the right application.
- LatencyNetworking, p. 14Latency is the delay between sending a request and the start of a response, usually measured in milliseconds, and it shapes how responsive an app feels.
- DNSDevOps & Cloud, p. 16DNS is the internet's naming system that translates human-readable domain names like example.com into the numeric IP addresses computers use to connect.
- IP AddressNetworking, p. 10An IP address is a numeric label assigned to each device on a network so that data can be routed to it, much like a postal address for a house.
Sources
Spotted a mistake or something missing on this page?Suggest an edit