UDP — User Datagram Protocol
UDP (User Datagram Protocol) is a connectionless transport-layer protocol used to send data quickly with low overhead.
Unlike TCP, UDP does not establish a connection before sending data and does not provide built-in guarantees that data will arrive, arrive only once, or arrive in order.
Exam definition
UDP is a connectionless transport-layer protocol that provides fast, low-overhead datagram delivery without built-in guarantees of reliability, ordering, retransmission, or flow control.
UDP operates at:
OSI Model: Layer 4 → Transport Layer TCP/IP Model: Transport Layer
1. Where UDP Fits
A typical communication stack can look like:
Application │ │ DNS / DHCP / MQTT / QUIC ↓ Transport │ │ UDP ↓ Internet │ │ IP ↓ Network Access │ │ Ethernet / Wi-Fi ↓ Network
For example:
DNS ↓ UDP ↓ IP ↓ Wi-Fi
2. Why Do We Need UDP?
TCP provides many useful features:
Connection Acknowledgments Retransmission Ordering Flow control Congestion control
But these mechanisms add overhead and can introduce delay.
Some applications prefer:
Speed and low overhead rather than TCP-style reliability.
That's where UDP is useful.
3. Main Features of UDP
UDP is:
- Connectionless
- Lightweight
- Fast/low overhead
- Datagram-oriented
- No handshake
- No built-in retransmission
- No built-in ordering
- No TCP-style flow control
- No TCP-style congestion control
- Uses port numbers
- Has a small header
4. UDP Is Connectionless
TCP:
Connection establishment ↓ Data transfer ↓ Connection termination
UDP:
Send datagram ↓ Send datagram ↓ Send datagram
There is no TCP-style three-way handshake.
Example:
Client Server UDP Datagram ─────────────────> UDP Datagram ─────────────────> UDP Datagram ─────────────────>
The sender does not first need to establish a TCP connection.
5. UDP Datagram
The unit of data handled by UDP is called a:
UDP datagram
Basic structure:
┌─────────────────────────────┐ │ UDP Header │ ├─────────────────────────────┤ │ Application Data │ └─────────────────────────────┘
Compare:
TCP → Segment UDP → Datagram IP → Packet Ethernet → Frame
6. UDP Header
The UDP header is only 8 bytes.
0 15 16 31 ┌─────────────────┬─────────────────┐ │ Source Port │ Destination Port│ ├─────────────────┼─────────────────┤ │ Length │ Checksum │ └─────────────────┴─────────────────┘
It contains only four fields:
- Source Port
- Destination Port
- Length
- Checksum
7. Source Port
The source port identifies the sending application endpoint.
Example:
Client: 192.168.1.10:53000
Here:
53000
is the source port.
8. Destination Port
The destination port identifies the service receiving the datagram.
For DNS:
Client:53000 ↓ Server:53
So:
Destination Port = 53
9. Length
The UDP length field specifies the length of:
UDP Header + UDP Data
The minimum UDP datagram size is 8 bytes, because the header itself is 8 bytes.
10. Checksum
UDP uses a checksum for error detection.
It helps detect whether the datagram was corrupted during transmission.
Conceptually:
Sender ↓ Calculate checksum ↓ Send UDP Datagram ↓ Receiver ↓ Verify checksum
Important:
A checksum detects corruption; it does not make UDP reliable like TCP.
11. UDP Does Not Have a Handshake
TCP:
Client Server SYN ─────────────────> <──────── SYN-ACK ACK ─────────────────> Connection established
UDP:
Client Server Datagram ────────────>
That's it.
This reduces startup overhead.
12. UDP Does Not Guarantee Delivery
Suppose:
Client │ ├── Datagram 1 ─────→ Server ├── Datagram 2 ─────→ Server ├── Datagram 3 ──X └── Datagram 4 ─────→ Server
UDP itself does not automatically retransmit Datagram 3.
There is no TCP-style built-in acknowledgment/retransmission mechanism.
If an application requires reliability, it must implement it itself or use a higher-level protocol.
13. UDP Does Not Guarantee Ordering
Suppose the sender sends:
1 2 3 4
The receiver could receive:
1 3 4 2
UDP itself does not reorder those datagrams into the original sequence.
If ordering is important, the application/protocol must handle it.
14. UDP Does Not Provide TCP-Style Flow Control
TCP can tell the sender:
"My receive buffer has limited space; slow down."
UDP does not provide TCP's receive-window mechanism.
For example:
Fast Sender │ │ UDP ↓ Slow Receiver
The application and underlying system must handle the consequences.
15. UDP Does Not Provide TCP-Style Congestion Control
TCP actively adjusts its sending behavior based on network conditions.
Basic UDP itself does not provide TCP's congestion-control algorithm.
This can be useful for applications that need to control timing themselves, but poorly designed UDP traffic can contribute to network congestion.
16. UDP Is Datagram-Oriented
This is an important difference from TCP.
Suppose an application sends:
Message A Message B Message C
UDP preserves the datagram/message boundaries.
Conceptually:
Datagram A → separate Datagram B → separate Datagram C → separate
TCP instead provides a byte stream:
ABC...
without preserving application message boundaries.
17. TCP vs UDP Data Model
TCP
Application ↓ Byte Stream ↓ TCP
TCP doesn't know where one application message ends and another begins.
UDP
Application ↓ Datagram ↓ UDP
Each send operation corresponds to a separate UDP datagram.
18. UDP Example — DNS
DNS commonly uses UDP.
For example:
Client DNS Server UDP Source Port: 53000 Destination: 53 │ │ DNS Query └──────────────────────> DNS Response <──────────────────────┘
Traditional DNS commonly uses:
UDP 53
DNS can also use TCP 53, for example when required by the protocol or response conditions.
19. UDP Example — DHCP
DHCP uses UDP.
Common ports:
DHCP Server → UDP 67 DHCP Client → UDP 68
A simplified process:
Client DHCP Server UDP 68 │ │ DHCP Discover ├─────────────────────────> UDP 67 │ │ DHCP Offer │<───────────────────────── │
UDP is useful here because a client may initially have little or no IP configuration.
20. UDP and IoT
UDP is especially useful in some IoT applications.
For example:
ESP32 │ │ UDP ↓ Local Server
An ESP32 could periodically send:
Temperature: 28.4 Humidity: 65
For sensor telemetry where occasional packet loss is acceptable, UDP can be a practical choice.
For more complex IoT messaging, protocols such as MQTT commonly run over TCP.
21. UDP and Real-Time Applications
UDP is often useful where timeliness is more important than retransmitting old data.
Examples include:
- Voice communication
- Video communication
- Online gaming
- Real-time telemetry
- Some streaming systems
- Certain discovery protocols
Imagine a live voice call.
Suppose one audio packet is lost:
Audio 101 → received Audio 102 → lost Audio 103 → received
Waiting a long time to retransmit old audio may be worse than simply continuing.
The application may prefer:
Keep playing newer audio
rather than:
Stop everything Wait for packet 102 Then continue
This is one reason UDP is useful for real-time applications.
22. Important Modern Example — QUIC
One of the most important modern uses of UDP is QUIC.
HTTP/3 uses:
HTTP/3 ↓ QUIC ↓ UDP ↓ IP
QUIC implements many transport features above UDP, including:
- Reliable delivery mechanisms
- Encryption through TLS 1.3 integration
- Stream multiplexing
- Connection migration
- Congestion control
So UDP itself is simple, but applications/protocols can build sophisticated functionality on top of it.
23. UDP and HTTP/3
Traditional HTTP:
HTTP/1.1 ↓ TCP ↓ IP
HTTP/2 commonly:
HTTP/2 ↓ TCP + TLS ↓ IP
HTTP/3:
HTTP/3 ↓ QUIC ↓ UDP ↓ IP
Therefore:
Modern web networking is not exclusively TCP-based.
24. UDP Port Numbers
UDP has its own port namespace.
Common examples:
| Port | Protocol | Purpose |
|---|---|---|
| 53 | DNS | Domain name resolution |
| 67 | DHCP | DHCP server |
| 68 | DHCP | DHCP client |
| 69 | TFTP | Trivial File Transfer |
| 123 | NTP | Time synchronization |
| 161 | SNMP | Network management |
| 162 | SNMP | Traps/notifications |
| 500 | IKE | IPsec negotiation |
| 514 | Syslog | Commonly used for syslog |
| 1900 | SSDP | Device/service discovery |
| 5353 | mDNS | Multicast DNS |
Port numbers alone do not prove what application is actually running.
25. TCP and UDP Have Separate Port Spaces
This is important.
TCP:
TCP 53
and UDP:
UDP 53
are different transport endpoints.
A machine can technically have:
TCP 53 UDP 53
at the same time.
For example, DNS commonly uses both TCP and UDP port 53.
26. UDP Socket
A UDP endpoint can be represented using:
IP:Port
For example:
192.168.1.10:53000
A UDP communication flow can be described using:
Protocol Source IP Source Port Destination IP Destination Port
For example:
UDP 192.168.1.10:53000 ↓ 8.8.8.8:53
27. UDP Broadcast
UDP can be used with broadcast in IPv4 networks.
Example:
Client │ │ UDP Broadcast ↓ Local Network ┌───┬───┬───┬───┐ PC 1 PC 2 PC 3 Server
A single datagram can reach multiple hosts on the local network when the application/network supports it.
28. UDP Multicast
UDP also supports multicast-based applications.
Example:
Sender │ ↓ Multicast Group / | \ PC1 PC2 PC3
This is useful for certain:
- Streaming systems
- Service discovery
- Routing protocols
- IoT/network discovery applications
29. UDP Unicast
Normal one-to-one communication is called unicast.
Client │ │ UDP ↓ Server
Examples include many DNS queries and application-specific UDP protocols.
30. UDP Maximum Size
The UDP length field is 16 bits, so the theoretical maximum UDP datagram size is:
65,535 bytes
But practical usable payload size is lower because the UDP header and IP headers consume space.
Also, sending very large UDP datagrams can lead to IP fragmentation, which is generally undesirable for many applications.
For IPv4:
Maximum IP packet = 65,535 bytes
UDP itself has an 8-byte header.
31. UDP Fragmentation
Suppose:
Large UDP Datagram ↓ Network MTU too small ↓ IP fragmentation may occur
If a fragment is lost, the complete original IP datagram may become unusable.
This is one reason applications generally avoid unnecessarily large UDP datagrams.
32. UDP and Reliability
A common misconception is:
"UDP is unreliable, so it is bad."
That's not necessarily true.
UDP is intentionally simple.
An application can build its own reliability.
For example:
Application ├── Sequence numbers ├── ACK ├── Retransmission └── Timeout ↓ UDP
So:
UDP itself → no TCP-style reliability Application → can implement reliability if needed
QUIC is an important real-world example of this design approach.
33. UDP Security
UDP itself does not provide encryption.
For example:
UDP ↓ IP
doesn't automatically mean the data is encrypted.
Security can be added by higher-level protocols.
Examples:
DNS ↓ DoT / DoH
or:
QUIC ↓ TLS 1.3 ↓ UDP
34. UDP Scanning
From a cybersecurity/network administration perspective, UDP services can be checked using tools such as Nmap in an authorized environment.
For example:
nmap -sU 192.168.1.10
-sU requests UDP scanning.
UDP scanning can be more difficult than TCP scanning because:
- Open UDP services may not respond to every probe.
- ICMP errors can indicate some states.
- Firewalls may filter responses.
- Applications may respond only to valid protocol requests.
Use scanning only on systems you own or are authorized to test.
35. UDP in Linux
You can view UDP sockets using:
ss -u
Listening UDP sockets:
ss -lun
With process information:
ss -lunp
You may see something like:
UNCONN 0 0 0.0.0.0:53
UNCONN here reflects the fact that UDP does not maintain TCP-style connection states.
36. UDP vs TCP — Detailed Comparison
| Feature | TCP | UDP |
|---|---|---|
| Full form | Transmission Control Protocol | User Datagram Protocol |
| Layer | Transport | Transport |
| Connection | Connection-oriented | Connectionless |
| Handshake | Yes | No |
| Data unit | Segment | Datagram |
| Reliability | Built-in | Not built-in |
| Ordering | Built-in | Not built-in |
| ACK | Yes | No TCP-style ACK |
| Retransmission | Yes | No built-in |
| Flow control | Yes | No TCP-style mechanism |
| Congestion control | Yes | No TCP-style mechanism |
| Header | Minimum 20 bytes | 8 bytes |
| Message boundaries | Not preserved | Preserved |
| Overhead | Higher | Lower |
| Latency | Can be higher | Often lower overhead |
| Broadcast | No | IPv4 supports it |
| Multicast | No | Commonly used |
| Typical use | Web, SSH, file transfer | DNS, DHCP, real-time traffic, QUIC |
| Speed | Reliable and controlled | Lightweight and application-dependent |
37. TCP vs UDP Simple Example
Imagine sending 100 packets.
TCP
Send ↓ ACK ↓ Send ↓ ACK ↓ Missing packet? ↓ Retransmit
UDP
Send Send Send Send Send
UDP doesn't automatically wait for acknowledgment or retransmit missing datagrams.
38. Real-World Analogy
Imagine sending letters.
TCP
It's like a courier service that:
✓ Tracks delivery ✓ Confirms receipt ✓ Maintains order ✓ Resends missing packages ✓ Controls how much is sent
UDP
It's more like sending individual postcards:
Send → Done Send → Done Send → Done
You don't automatically receive a delivery confirmation from UDP.
39. UDP Communication Flow
Complete simplified architecture:
APPLICATION │ ┌──────────┴──────────┐ │ │ DNS QUIC │ │ └──────────┬──────────┘ ↓ UDP │ ┌──────────┴──────────┐ │ │ Port 53 Port 443 │ │ └──────────┬──────────┘ ↓ IP ↓ Ethernet / Wi-Fi ↓ Network
40. Important UDP Characteristics
Remember these:
UDP │ ├── Connectionless ├── No handshake ├── Lightweight ├── 8-byte header ├── Uses ports ├── Datagram-oriented ├── No built-in retransmission ├── No built-in ordering ├── No TCP-style flow control ├── No TCP-style congestion control └── Low protocol overhead
41. UDP — Exam Questions
Q1. What is UDP?
UDP is a connectionless transport-layer protocol that provides lightweight datagram delivery without TCP-style guarantees of reliability, ordering, retransmission, flow control, or congestion control.
Q2. What is the UDP header size?
8 bytes
Q3. Does UDP use ports?
Yes.
Q4. Does UDP perform a three-way handshake?
No.
Q5. Does UDP guarantee delivery?
No.
Q6. Does UDP guarantee packet ordering?
No.
Q7. Give common UDP protocols.
Examples:
DNS DHCP NTP SNMP QUIC
Q8. What is the difference between TCP and UDP?
TCP provides connection-oriented, reliable, ordered byte-stream transport, while UDP provides connectionless, lightweight datagram transport without TCP-style reliability and ordering guarantees.
42. Most Important Memory Trick
Remember:
TCP T = Tracking / Trust C = Connection P = Provides reliability
And:
UDP U = User D = Datagram P = Protocol
But for exams, remember the actual concepts rather than relying only on the mnemonic:
TCP → Reliable + Ordered + Connection-oriented UDP → Lightweight + Connectionless + Datagram-oriented
43. Final TCP vs UDP Picture
TRANSPORT LAYER │ ┌─────────┴─────────┐ │ │ TCP UDP │ │ Connection-oriented Connectionless │ │ Reliable Lightweight │ │ Ordered Unordered │ │ Retransmission No built-in │ retransmission │ │ Flow control No TCP-style │ flow control │ │ Congestion control No TCP-style │ congestion control │ │ Byte stream Datagram
One-line answer to remember
UDP is a connectionless, lightweight, transport-layer protocol that sends independent datagrams using port numbers, without providing TCP-style guarantees of delivery, ordering, retransmission, flow control, or congestion control.