c2cedge
LibraryCS Fundamentals › Ch 13
CS Fundamentals · C — Computer Networks

Transport Layer: TCP vs UDP

The transport layer delivers data between applications. TCP-vs-UDP is one of the single most-asked networking questions — know it cold.

Test weight: Very highAsked by: All recruitersDifficulty: Medium

The transport layer moves data between applications on two hosts, identified by port numbers. The two protocols are TCP (reliable, connection-oriented) and UDP (fast, connectionless). Choosing between them — and the TCP three-way handshake — are guaranteed interview topics.

Reliable vs fast

TCP sets up a connection, guarantees ordered, error-checked, reliable delivery with flow and congestion control — at the cost of overhead. UDP just fires datagrams with no connection or guarantees — minimal overhead and latency, but packets may be lost or reordered.

AspectTCPUDP
Connectionyes (handshake)no
Reliabilityguaranteed, orderedbest-effort
Speed/overheadslower, more overheadfast, low overhead
Use casesweb, email, file transfervideo/voice, gaming, DNS
⚡ The edge
  • Pick by need: TCP when correctness matters (web pages, files, email); UDP when speed matters more than perfection (live video, voice, gaming).
  • The TCP three-way handshake is SYN → SYN-ACK → ACK — the client and server agree on sequence numbers before any data flows.
Worked example
'When would you choose UDP over TCP?'
  1. UDP suits real-time data where a late packet is useless and retransmission would only add lag.
  2. Examples: live video/voice calls, online gaming, and DNS lookups (small, fast, retried by the app).
  3. You accept occasional loss in exchange for low latency and no handshake overhead.
Worked example
'Explain the TCP three-way handshake.'
  1. The client sends SYN with an initial sequence number.
  2. The server replies SYN-ACK, acknowledging the client and sending its own sequence number.
  3. The client replies ACK; both sides now agree on sequence numbers and the connection is established.
⚠ Watch out
  • UDP is not 'unreliable garbage' — it's deliberately lightweight for cases where speed matters most.
  • TCP provides ordering and reliability; UDP does not — the application must handle loss if it cares.
  • Ports (not IPs) identify the application; IP identifies the host.
Practice this — take a timed mock →
1,300+ questions, scored, with a weak-area report.
Know who's ready. Not who finished.
HomeLibraryPrivacyTerms