Sub topic 3
TCP versus UDP
This chapter assumes you know what a network packet is and have read the OSI and TCP/IP overview. You should also be comfortable with the idea that applications talk to each other across a network. TCP and UDP are the two transport protocols that carry most application data. A+ Core 1 expects you to tell them apart and match each to the services that use it.
The working model
Both protocols sit at the transport layer. They take data from an application, label it with port numbers, and hand it to IP for delivery. They differ in how much care they take on the way.
- TCP (Transmission Control Protocol) is connection-oriented. The two hosts set up a session first, then exchange data, then close the session.
- UDP (User Datagram Protocol) is connectionless. A host sends each datagram without setting anything up and without checking whether it arrived.
TCP is often described as reliable, and UDP as best-effort. "Reliable" here means TCP detects loss and fixes it. It does not mean TCP is faster or safer.
How TCP builds a connection
TCP opens a session with a three-way handshake.
After the handshake, TCP numbers each segment (a unit of TCP data). The receiver acknowledges what it gets, and the sender retransmits anything not acknowledged. TCP also puts segments back in order and slows down if the receiver or network is overloaded (flow control). This extra work adds overhead and delay.
How UDP behaves
UDP has no handshake, no acknowledgments, no retransmission and no ordering. Its header is small and the protocol adds little delay. If a datagram is lost, UDP does nothing. The application must tolerate the loss or handle it itself.
Comparison
| Feature | TCP | UDP |
|---|---|---|
| Connection | Connection-oriented | Connectionless |
| Delivery | Acknowledged, retransmitted | Best-effort |
| Ordering | Guaranteed | Not guaranteed |
| Overhead | Higher | Lower |
| Typical use | Web, email, file transfer | Streaming, voice, DNS queries, DHCP |
Choosing the right one
Use TCP when every byte must arrive correctly. Examples are HTTP and HTTPS (80, 443), SMTP (25), FTP (20/21) and SSH (22). A web page with missing pieces is broken.
Use UDP when speed matters more than perfection, or when the exchange is a single short request and reply. Examples are DHCP (67/68), TFTP (69), SNMP (161/162), and voice or video streaming. A dropped frame in a call is better skipped than resent late.
Some services use both. DNS (53) normally uses UDP for small queries and switches to TCP for large responses. RDP (3389) can use both.
Common errors
- Assuming UDP is "unreliable" means broken. It is a deliberate design choice.
- Saying TCP is faster. It is slower per packet because of its overhead.
- Forgetting that a firewall rule or port forward must name the right protocol. Opening 69 for TCP does not help TFTP, which uses UDP.
Exercise
A technician configures port forwarding for a TFTP server and sets the rule to TCP port 69. Clients still cannot connect. What is the likely cause, and what is the fix?
Show answer
TFTP uses UDP port 69, so a TCP-only rule never matches its traffic. Change the rule to forward UDP port 69.
Exercise
Why does a video call prefer UDP over TCP?
Show answer
UDP has lower overhead and does not retransmit lost data. A late retransmitted packet is useless in a live call, so skipping it gives smoother real-time audio and video.