What Is the Difference Between TCP and UDP?
Question: What is the difference between TCP and UDP?
Core Answer
Both TCP and UDP are transport-layer protocols — they sit on top of IP and provide communication between applications on different machines. The key difference is:
| Feature | TCP | UDP |
|---|---|---|
| Connection | Connection-oriented (handshake first) | Connectionless (send freely) |
| Reliability | Guaranteed delivery, retransmission on loss | Best-effort (no retransmission) |
| Ordering | In-order delivery guaranteed | No ordering guarantee |
| Overhead | Higher (headers, ACKs, buffers) | Lower (minimal headers) |
| Use cases | Web, email, file transfer | Video calls, DNS, gaming |
TCP: Reliable, Ordered, Connection-Oriented
TCP establishes a connection before sending data, using the famous three-way handshake:
- Client sends
SYN(synchronize) - Server responds with
SYN-ACK(synchronize-acknowledge) - Client sends
ACK(acknowledge)
After the handshake, TCP numbers each byte with a sequence number and the receiver acknowledges received data with ACKs. If the sender doesn't receive an ACK within a timeout, it retransmits. If packets arrive out of order, TCP reassembles them in the right order.
This reliability comes at a cost: connection setup latency, per-packet overhead, and head-of-line blocking (if one packet is lost, later packets in the same stream must wait, even if they arrived).
UDP: Fast, Simple, Best-Effort
UDP has no connection setup — the sender just starts sending packets. There is no retransmission, no ordering, no flow control. Each UDP datagram is independent. If a packet is lost, the sender doesn't know and doesn't retry.
This makes UDP ideal for:
- Real-time media (video calls, live streaming) — a dropped frame is better than a delayed frame
- DNS — quick request/response, can retransmit at the application layer if needed
- Gaming — low latency matters more than every packet arriving
- Broadcast/multicast — sending to many receivers at once
The Trade-off
TCP trades speed for reliability. UDP trades reliability for speed. The choice depends on whether your application can tolerate loss and whether it needs ordering guarantees.
Further Reading
- TCP Transport article — reliability, flow control, and connection semantics
- Trace: A Packet Through Network Layers
- What Is a Network?