TCP vs UDP - What's the Difference?
TCP (Transmission Control Protocol) and UDP (User Datagram Protocol) are the two dominant transport-layer protocols that applications use to send data over IP networks. They represent a fundamental trade-off between reliability and speed - Understanding this trade-off explains why your web browser and your online game feel completely different under the hood.
TCP vs UDP Comparison
| Property | TCP | UDP |
|---|---|---|
| Connection model | Connection-oriented - 3-way handshake before data transfer | Connectionless - Data sent immediately, no setup |
| Reliability | Guaranteed delivery - Lost packets are retransmitted | Best-effort - Lost packets are not retransmitted |
| Ordering | Packets delivered in order; out-of-order packets buffered | No ordering guarantee - Application handles if needed |
| Error checking | Checksum + acknowledgement + retransmission | Checksum only - No retransmission |
| Flow control | Yes - Sliding window adjusts send rate to receiver capacity | No |
| Congestion control | Yes - CUBIC, BBR, Reno algorithms | No - Application must implement if needed |
| Header size | 20–60 bytes | 8 bytes |
| Speed | Slower - Overhead from reliability mechanisms | Faster - Minimal overhead |
| Typical use cases | HTTP/HTTPS, email (SMTP/IMAP), file transfer (FTP), SSH | DNS, video/audio streaming, VoIP, online gaming, QUIC |
The TCP 3-Way Handshake
Before any data is exchanged over TCP, a connection is established in three steps: (1) the client sends a SYN packet with a random initial sequence number; (2) the server responds with SYN-ACK, acknowledging the client's sequence number and sending its own; (3) the client sends ACK, acknowledging the server's sequence number. Only after this handshake does application data begin to flow. This adds one round-trip time (RTT) of latency before the first byte of data - A significant overhead for short-lived connections like DNS queries.
When to Use Each Protocol
- Use TCP (or protocols built on TCP) when data integrity is critical: web browsing, file downloads, email, database queries. See HTTP vs HTTPS for how TCP underpins web traffic.
- Use UDP when low latency is more important than guaranteed delivery: live video streaming, VoIP calls, DNS lookups, online games.
- QUIC (used in HTTP/3) runs over UDP but re-implements reliability, ordering, and congestion control at the application layer - Getting the best of both worlds.
- WireGuard VPN uses UDP, which makes it faster and more resilient to network interruptions than OpenVPN (which can use TCP or UDP).
- DNS uses UDP for standard queries (faster) but falls back to TCP for responses larger than 512 bytes.