Skip to main content
CSNetworkingDiagramBeginner

TCP vs UDP

KO: TCP vs UDP·EN: TCP vs UDP·JA: TCP vs UDP·Transmission Control Protocol vs User Datagram Protocol

Comparing TCP (reliable, ordered, connection-oriented transport) against UDP (lightweight, connectionless datagrams optimized for low latency)

Table of Contents

Structure Diagram

TCP (Reliable Connection) vs UDP (Low-Latency Datagram)
TCPTCP (Transmission Control)

3-Way Handshake · Ordered & reliable

  • ConnectionConnection-oriented (3-Way Handshake)
  • ReliabilityACK + retransmission + strict ordering
  • Header Size20+ bytes (flow & congestion control)
  • Use CasesHTTP/1.1 & 2, SSH, email, file transfers
UDPUDP (User Datagram)

Connectionless fire-and-forget · Ultra-low latency

  • ConnectionConnectionless (no handshake delay)
  • ReliabilityBest-effort (drop stale packets)
  • Header SizeFixed 8 bytes (minimal overhead)
  • Use CasesOnline FPS, WebRTC, DNS, HTTP/3 (QUIC)
Quick Answer

What is TCP vs UDP?

Comparing TCP (reliable, ordered, connection-oriented transport) against UDP (lightweight, connectionless datagrams optimized for low latency). It is a core concept in Networking within CS.

Core Principles

TCP and UDP are the two primary transport-layer (L4) protocols powering the internet, embodying a fundamental engineering tradeoff between reliability and latency.

  • TCP establishes a session via a 3-way handshake, numbers every segment, confirms delivery with ACKs, retransmits lost packets, and throttles throughput via congestion control. This guarantees an exact, ordered byte stream—at the cost of higher overhead and Head-of-Line (HOL) blocking whenever a single packet drops.
  • UDP skips handshakes and retransmissions altogether, wrapping payloads in an 8-byte header and sending them immediately. When a packet is lost, stale audio or an outdated player coordinate is simply skipped in favor of the newest frame.

Practical Takeaways

  • Choose TCP for accuracy, UDP for freshness: Web APIs, financial transactions, file transfers, and database connections require TCP. Live voice/video calls (WebRTC) and fast-paced multiplayer games favor UDP because late data is worse than missing data.
  • QUIC (HTTP/3) blends the best of both worlds: To escape TCP's HOL blocking and slow connection setup on flaky mobile networks, HTTP/3 runs QUIC over UDP—implementing multiplexed streams, built-in TLS 1.3, and fast loss recovery in user space.
  • Use Reliable UDP selectively in game netcode: Real-time games typically send frequent position snapshots over raw UDP while layering lightweight custom reliability (e.g., ENet, KCP) only for critical discrete events like inventory changes or match results.

Notable Examples

  • TCP: HTTP/1.1 & HTTP/2, SSH, SMTP/IMAP email, and database wire protocols (PostgreSQL, MySQL).
  • UDP: DNS lookups, live voice/video conferencing (WebRTC, Discord Voice), and competitive FPS netcode.
  • HTTP/3 (QUIC): Deployed across Cloudflare, Google, and YouTube to accelerate mobile web traffic under packet loss.