TCP (Transmission Control Protocol)
Connection-oriented, reliable, ordered. Before sending data, TCP establishes a connection via a three-way handshake.
| Property | Details |
|---|---|
| Connection | 3-way handshake (SYN, SYN-ACK, ACK) |
| Reliability | ACKs every segment, retransmits lost ones |
| Ordering | Sequence numbers ensure in-order delivery |
| Flow control | Prevents overwhelming the receiver |
| Congestion control | Prevents overwhelming the network |
| Header size | 20-60 bytes |
| Use cases | HTTP, SMTP, FTP, SSH |
UDP (User Datagram Protocol)
Connectionless, best-effort, no ordering. “Fire and forget.”
| Property | Details |
|---|---|
| Connection | None — just send |
| Reliability | No ACKs, no retransmission |
| Ordering | No guarantee |
| Flow/congestion control | None |
| Header size | 8 bytes |
| Use cases | DNS, VoIP, video streaming, gaming |
Comparison
| Feature | TCP | UDP |
|---|---|---|
| Connection setup | 3-way handshake | None |
| Reliability | Guaranteed delivery | Best effort |
| Speed | Slower (overhead) | Fast (minimal overhead) |
| Data ordering | Preserved | Not preserved |
| Header overhead | 20+ bytes | 8 bytes |
| Use when | Accuracy matters | Speed/latency matters |
Why Games Use UDP
In a fast-paced game, a lost packet containing a player’s position is obsolete a few milliseconds later. TCP would pause and retransmit the old data, causing lag (“rubber banding”). UDP keeps sending the latest position, accepting occasional loss for lower latency.
Q: Key differences between TCP and UDP?
A: TCP is connection-oriented, reliable, and ordered — but slower. UDP is connectionless, best-effort, and faster. Use TCP for accuracy (web, email). Use UDP for speed (streaming, gaming, DNS queries).
Q: Why do online games use UDP?
A: Because a new player position is more important than an old one. TCP retransmitting a lost packet would introduce lag. UDP accepts packet loss for speed — the game just uses the most recent update.
Q: Can UDP be made reliable?
A: Yes — the application layer can add ACKs, sequence numbers, and retransmission on top of UDP. QUIC (HTTP/3) does exactly this: reliable data over UDP, avoiding TCP head-of-line blocking.
Premium Content
Unlock TCP vs UDP and all premium lessons with a subscription.
From ₹199.99/year — See plans