TCP vs UDP: The Three-Way Handshake and When Each One Wins
Every Computer Networks viva has the question: "What is the difference between TCP and UDP?" Most students recite a table. The answer that earns marks explains why each protocol exists.
The problem both protocols sit on top of
IP delivers packets on a best-effort basis. A packet can be lost, duplicated, delayed, or arrive out of order. IP does not care. The transport layer decides how much of that mess the application has to see.
- TCP hides the mess: the application gets a reliable, ordered stream of bytes.
- UDP exposes the mess: the application gets individual datagrams, with whatever happened to them in transit.
TCP: a connection before data
TCP is connection-oriented. Before any data moves, both sides agree they are talking to each other, using a three-way handshake.
- SYN: the client sends a segment with the SYN flag and its initial sequence number, say
x. ("I want to talk. My numbering starts at x.") - SYN-ACK: the server replies with SYN and ACK, its own initial sequence number
y, and acknowledgement numberx + 1. ("Heard you. My numbering starts at y.") - ACK: the client sends ACK with acknowledgement number
y + 1. ("Heard you too. Let's go.")
Why three steps and not two? Because each side must prove it can both send and receive, and each side's sequence number must be acknowledged by the other. After step 2 the server knows the client can send, but it cannot yet be sure the client received the server's reply. Step 3 closes that gap.
What the handshake buys you
- Sequence numbers let the receiver put segments back in order and detect missing ones.
- Acknowledgements and retransmission resend anything that was lost.
- Flow control (the receiver advertises a window) stops a fast sender flooding a slow receiver.
- Congestion control slows the sender when the network is overloaded.
Each of these costs time and extra bytes. TCP's header is at least 20 bytes, and a connection has to be set up and torn down.
UDP: just send it
UDP has no handshake, no acknowledgements, no ordering and no retransmission. Its header is 8 bytes: source port, destination port, length and checksum. You hand it a datagram and it sends it.
That sounds like a weakness, but it is a deliberate trade:
- No setup delay. The first packet carries data.
- No head-of-line blocking. One lost packet does not hold up the later ones.
- Small and cheap. A server can handle a huge number of tiny requests.
When each one wins
| Use case | Protocol | Why |
|---|---|---|
| Web pages (HTTP/HTTPS over TCP) | TCP | A missing byte corrupts the page |
| File transfer, email | TCP | Every byte must arrive, in order |
| DNS lookups | UDP | One tiny question, one tiny answer; retry is cheap |
| Live video or voice calls | UDP | A late packet is useless; better to skip it than wait |
| Online games | UDP | Fresh position beats an old retransmitted one |
A good viva answer on video calls: "If a packet carrying 20 ms of audio is lost, retransmitting it makes it arrive too late to play. Skipping it costs a tiny glitch. Waiting for it makes everything after it stall." That is the whole argument for UDP.
A common confusion
"UDP is unreliable, so nobody uses it for anything important." Not true. Protocols built on UDP, such as QUIC (which carries much of today's web traffic), implement their own reliability selectively, exactly where they need it, without TCP's one-size-fits-all behaviour.
The two-line viva answer
TCP gives the application a reliable, ordered byte stream, at the cost of a handshake and extra overhead. UDP gives the application raw datagrams with almost no overhead and leaves reliability, if needed, to the application.
Sumantrak™ is an AI mentor built for Indian engineering, diploma, BCA and BSc CS/IT students — Operating Systems, Networks, and the rest of your syllabus, explained like this. Free to start →