Skills101

Computer Networks · Lesson 4 of 7 · Updated ·

TCP vs UDP — Three-Way Handshake, Reliability, Flow and Congestion Control

Both TCP and UDP carry data between applications using port numbers. The difference is how much they promise.

TCP vs UDP table: TCP is connection-based, reliable, ordered, slower, with a 20+ byte header, used by web and email; UDP is connectionless, unreliable, unordered, fast, 8-byte header, used by video calls, games and DNS

1. TCP: reliable, ordered delivery

The three-way handshake

Client sends SYN (seq = x); server replies SYN-ACK (seq = y, ack = x+1); client sends ACK (ack = y+1); the connection is established

  1. SYN — client: "I want to talk; my starting sequence number is x."
  2. SYN-ACK — server: "OK; mine is y; I got yours (ack x+1)."
  3. ACK — client: "Got yours (ack y+1)." → connected.

Closing uses FIN and ACK from both sides (four steps).

How TCP makes delivery reliable

  • Sequence numbers — every byte is numbered, so the receiver can put segments in order.
  • Acknowledgements (ACKs) — the receiver confirms what arrived.
  • Retransmission — if no ACK arrives in time, the sender resends.
  • Checksum — detects corrupted data.

Flow control vs congestion control

Flow controlCongestion control
Protectsthe receiver from being floodedthe network from overload
Howreceiver advertises a window (how much it can accept)slow start, then additive increase / multiplicative decrease

2. UDP: fast and simple

UDP just sends datagrams — no connection, no ACKs, no ordering, no retransmission. Its header is only 8 bytes.

Why would anyone want that? Because for some apps, late data is useless:

  • In a video call, a frame that arrives 2 seconds late is worse than a skipped frame.
  • Online games send the latest position many times a second.
  • DNS queries are tiny; if one is lost, the app just asks again.

3. Which one does each app use?

AppProtocolPort
Web (HTTP / HTTPS)TCP (HTTP/3 uses QUIC over UDP)80 / 443
SSHTCP22
Email (SMTP)TCP25 / 587
MySQL / PostgreSQLTCP3306 / 5432
DNSUDP (TCP for big answers)53
DHCPUDP67 / 68
Video calls, live streaming, gamesmostly UDPvarious

Port ranges: 0–1023 well-known, 1024–49151 registered, 49152–65535 dynamic (your browser's side of a connection).

4. Sockets

A socket = IP address + port. A TCP connection is identified by both ends: (client IP, client port, server IP, server port). That's how one server on port 443 handles thousands of users at once.

Common mistakes

  • Saying UDP is "bad". It's the right choice for real-time traffic.
  • Confusing flow control (receiver) with congestion control (network).
  • Thinking the handshake has 2 steps — it's 3 (SYN, SYN-ACK, ACK).

Quick recap

  • TCP: connection (3-way handshake), sequence numbers, ACKs, retransmission, flow and congestion control.
  • UDP: no connection, no guarantees, small header, very fast.
  • TCP for correctness (web, email, files); UDP for real-time (calls, games, DNS).
  • Socket = IP + port; connections are identified by both ends.

Practice what you learned

📝 Quiz: TCP vs UDP5 questions · instant answers & explanations · +10 XP · counts towards your free certificateTake the quiz →