TCP vs UDP & 3-Way Handshake

TCP provides reliable, ordered, connection-oriented delivery; UDP is lightweight, connectionless and best-effort.

Cheat sheet

  • ▸Handshake: SYN → SYN-ACK → ACK.
  • ▸Termination: FIN → ACK → FIN → ACK (4-way).
  • ▸TCP features: sequence numbers, ACKs, retransmission, flow control (sliding window), congestion control.
  • ▸Congestion control: slow start, congestion avoidance, fast retransmit, fast recovery.
  • ▸UDP header = 8 bytes; TCP header = 20–60 bytes.
  • ▸UDP uses: DNS, video streaming, gaming, VoIP.

TCP vs UDP

AspectTCPUDP
ConnectionConnection-orientedConnectionless
ReliabilityGuaranteed, orderedBest effort
SpeedSlowerFaster
Header20–60 B8 B
UseWeb, email, file transferDNS, streaming, games

Visual

Client                Server
  │──── SYN (seq=x) ────▶│
  │◀─ SYN-ACK (y, x+1) ──│
  │──── ACK (y+1) ──────▶│   connection ESTABLISHED

Top 10 campus interview questions

Quick quiz

1. Second message of the TCP handshake:

2. UDP header size:

3. Which protocol suits live video calls?

4. Receiver-side window prevents:

5. HTTPS default port: