Networking · Topic 1 of 10
TCP and UDP Compared
Compare TCP and UDP, including connection setup, reliability, speed and typical uses, and see how port numbers send traffic to the right service on a host.
- 4 min
- TCP is connection oriented and reliable; UDP is connectionless and best effort.
- The TCP handshake is SYN, then SYN ACK, then ACK.
- TCP resends lost data and puts data in order; UDP does neither.
What it is
Transmission Control Protocol (TCP) and User Datagram Protocol (UDP) are the two main transport protocols on an Internet Protocol (IP) network. They sit above IP and carry data between programs on two hosts.
TCP is careful and reliable. UDP is light and fast, but it does not guarantee delivery.
How it works
Both protocols use port numbers to say which program on a host should receive the data. They differ in what they do before and after the data is sent.
TCP: connection oriented
TCP sets up a connection before it sends data, using a three step exchange called the three way handshake.
The client sends a synchronise (SYN) message. The server replies with a synchronise acknowledgement (SYN ACK), and the client answers with an acknowledgement (ACK).
During the session TCP numbers the data and the receiver confirms each part. Lost parts are sent again, and parts that arrive out of order are put back in order.
TCP also slows down when the receiver or the network is overloaded. This makes TCP reliable, but it adds delay and overhead.
UDP: connectionless
UDP just sends the data. There is no handshake, no acknowledgement, no resending and no ordering.
This keeps the header small and the delay low. Any loss is either ignored or handled by the application. UDP suits traffic where speed matters more than perfect delivery.
Side by side
| Feature | TCP | UDP |
|---|---|---|
| Connection | Connection oriented, handshake first | Connectionless |
| Delivery | Guaranteed, with resending | Best effort, no guarantee |
| Order | Data is put back in order | No ordering |
| Overhead | Higher | Lower |
| Speed | Slower | Faster |
| Typical use | Web pages, email, file transfer, remote login | Voice, video streaming, online games, name lookups, address assignment |
Port numbers
A port is a number from 0 to 65535 that identifies a service on a host. A client address plus a port, written as an address and port pair, identifies one end of a conversation.
Port ranges are grouped by purpose.
| Range | Name | Use |
|---|---|---|
| 0 to 1023 | Well known ports | Standard services such as web and email |
| 1024 to 49151 | Registered ports | Applications registered with the port authority |
| 49152 to 65535 | Dynamic (ephemeral) ports | Temporary ports a client picks for a session |
When a browser contacts a web server, the server listens on a well known port, and the browser uses a random dynamic port as its own end.
Which one for which job
Some protocols use TCP, some use UDP and a few use both.
The Domain Name System (DNS) normally uses UDP for small lookups and TCP for large responses. The Dynamic Host Configuration Protocol (DHCP) uses UDP. File transfer and web traffic use TCP.
When a question stresses speed or live media with some loss allowed, choose UDP. When it stresses accuracy and complete delivery, choose TCP.
Firewalls and ports
A firewall rule often names the protocol and the port. If you open TCP port 443 but the service needs UDP, traffic will still be blocked. A rule must match both parts.
What to remember for the exam
- TCP is connection oriented and reliable; UDP is connectionless and best effort.
- The TCP handshake is SYN, then SYN ACK, then ACK.
- TCP resends lost data and puts data in order; UDP does neither.
- UDP has less overhead and suits voice, video and games.
- Ports run from 0 to 65535; 0 to 1023 are the well known ports.
- Clients pick a dynamic port for their end of a session.
- DNS uses UDP for most lookups and TCP for larger replies.
- A firewall rule must match the right protocol and the right port.
Common mistakes
Calling UDP unreliable and therefore bad. It is a design choice: the application may handle loss itself, or does not need every packet.
Assuming a service uses only one protocol. DNS uses both, so a rule that blocks UDP 53 alone can still leave TCP 53 open.
Mixing up a port with a protocol. A port is a number that points to a service on a host. TCP and UDP are the transport methods that carry the data.
Thinking TCP is always better. For live voice, the delay from resending old data is worse than a brief gap.
Forgetting the client port. The server listens on the well known port, but the client uses a temporary one.
Check yourself
What are the three steps of the TCP handshake?
SYN from the client, SYN ACK from the server, then ACK from the client.
Why is UDP chosen for live video?
It has low overhead and no resending delay, so the stream keeps moving even if a few packets are lost.
Which port range holds the well known service ports?
Ports 0 to 1023.
Topic 1 of 10 in Networking
Test yourself on Networking
The full CompTIA A+ 220-1201 question bank has 856 questions, with timed practice exams and an explanation for every answer.
This study guide is independent and is not affiliated with, endorsed by, or sponsored by CompTIA. Vendor names, certification names and exam codes are trademarks of their respective owners and are used for identification only.