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

PropertyTCPUDP
Connection modelConnection-oriented - 3-way handshake before data transferConnectionless - Data sent immediately, no setup
ReliabilityGuaranteed delivery - Lost packets are retransmittedBest-effort - Lost packets are not retransmitted
OrderingPackets delivered in order; out-of-order packets bufferedNo ordering guarantee - Application handles if needed
Error checkingChecksum + acknowledgement + retransmissionChecksum only - No retransmission
Flow controlYes - Sliding window adjusts send rate to receiver capacityNo
Congestion controlYes - CUBIC, BBR, Reno algorithmsNo - Application must implement if needed
Header size20–60 bytes8 bytes
SpeedSlower - Overhead from reliability mechanismsFaster - Minimal overhead
Typical use casesHTTP/HTTPS, email (SMTP/IMAP), file transfer (FTP), SSHDNS, 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.