TCP vs UDP — Side by Side

FeatureTCPUDP
ConnectionConnection-oriented (3-way handshake)Connectionless (no handshake)
ReliabilityGuaranteed delivery + retransmissionBest-effort, no guarantee
OrderingPackets delivered in orderMay arrive out of order
Error checkingChecksums + acknowledgementsChecksum only (no ACK)
SpeedSlower (overhead from reliability)Faster (minimal overhead)
Header size20–60 bytes8 bytes
Flow controlYes (sliding window)No
Congestion controlYesNo
Use casesHTTP, email, file transfer, SSHDNS, video streaming, gaming, VoIP

The TCP Three-Way Handshake

TCP must establish a connection before sending data. This costs one round trip:

Client → Server: SYN (I want to connect) Server → Client: SYN-ACK (OK, acknowledged) Client → Server: ACK (Great, let's go) --- Data transfer begins --- Client → Server: FIN (Done sending) Server → Client: FIN-ACK (Closing)

This handshake adds ~1 RTT of latency before any data flows. On a London-to-Singapore connection (150ms RTT), you pay 150ms just to open the connection. HTTP/2 reuses connections to amortise this cost; HTTP/3 (QUIC) eliminates the handshake entirely on resumed connections.

UDP — Fire and Forget

UDP sends packets (datagrams) directly with no setup:

Client → Server: data packet (no handshake) Client → Server: data packet (no acknowledgement) Client → Server: data packet (no retransmission)

If a packet is lost, it is gone. The application must decide whether to retransmit, skip it, or interpolate. This gives applications full control over the reliability trade-off.

When to Use TCP

  • HTTP/HTTPS: Web pages, REST APIs — data must be complete and correct
  • Email (SMTP, IMAP): Messages must arrive intact
  • File transfer (FTP, SFTP): Every byte must be delivered
  • SSH: Terminal commands must arrive in order
  • Database connections: Queries and results must be reliable

When to Use UDP

  • DNS: Small query/response — speed matters, retransmit is easy
  • Video streaming (WebRTC, RTP): Latency > reliability — drop a frame, not the call
  • Online gaming: Position updates — old data is worthless, just send the latest
  • VoIP: A 20ms audio glitch is better than a 500ms freeze
  • DHCP, TFTP: Simple protocols where reliability is handled at the application layer
  • Broadcast/multicast: UDP supports sending to multiple recipients simultaneously

QUIC — The Best of Both

QUIC (Quick UDP Internet Connections) is the transport protocol underlying HTTP/3. It is built on UDP but implements reliability, ordering, encryption, and multiplexing at the application layer. This lets it:

  • Avoid head-of-line blocking (one lost packet doesn't stall other streams)
  • Establish connections in 0 RTT on resumed sessions
  • Encrypt by default (TLS 1.3 built in)
  • Migrate connections when the client's IP changes (mobile networks)

💡 Protocol Port Numbers

TCP: HTTP 80, HTTPS 443, SSH 22, FTP 21, SMTP 25, MySQL 3306, PostgreSQL 5432.
UDP: DNS 53, DHCP 67/68, NTP 123, SNMP 161, QUIC/HTTP3 443.

How We Research and Update This Guide

We test the underlying formula or workflow, compare outputs with reliable references, and revise examples whenever the page content changes.

  • The workflow or formula is tested directly in the tool and compared against independent reference examples.
  • Examples are kept practical so readers can verify the result without hidden assumptions.
  • Pages are revised whenever the interface, calculation flow, or surrounding guidance materially changes.

Frequently Asked Questions — TCP vs UDP