TCP vs UDP and the Three-Way Handshake
Enterprise Network Engineer · Module 1: Networking Fundamentals
Lesson 6 of 8
Prerequisites: How Computers Talk: Packets, Frames, and Addresses, The OSI Model and TCP/IP: What Layers Actually Mean
What you'll be able to do: Read a three-way handshake in a capture, spot a lost packet by its numbers, and choose the right delivery style for any app.
Every message you send makes a tradeoff your gut already understands. A registered letter gets a tracking number, a signature on delivery, and a replacement if it vanishes — slow, but certain. A postcard gets tossed in the mail with no tracking at all — fast and cheap, but if a sorting machine eats it, nobody tells you. Networks face the same choice thousands of times a second: some messages must arrive perfectly and in order, and some — a live voice call, a game — would rather lose a piece than wait for a resend. The trick isn't picking the "better" one. It's knowing that before two computers exchange anything important, they first shake hands and agree on the rules — and that handshake leaves footprints you can read.
Here's the puzzle.
Scenario. A junior admin is troubleshooting a slow file download from the office file server. The download stalled for a third of a second, then recovered on its own. She captured 8 packets on the client and asks you three things: which piece went missing, how can you tell it was lost rather than merely delayed, and should this app have used the postcard instead of the registered letter?
Given artifacts. The lab link (hover any device for details):
Capture: Workstation → FileServer download (8 packets)
1 0.000 10.0.0.15 → 10.0.0.5 TCP [SYN] Seq=0
2 0.002 10.0.0.5 → 10.0.0.15 TCP [SYN, ACK] Seq=0 Ack=1
3 0.003 10.0.0.15 → 10.0.0.5 TCP [ACK] Seq=1 Ack=1
4 0.010 10.0.0.15 → 10.0.0.5 TCP Seq=1 Len=1000 (bytes 1–1000)
5 0.020 10.0.0.15 → 10.0.0.5 TCP Seq=1001 Len=1000 (bytes 1001–2000)
6 0.022 10.0.0.15 → 10.0.0.5 TCP Seq=2001 Len=1000 (bytes 2001–3000)
7 0.023 10.0.0.5 → 10.0.0.15 TCP [ACK] Ack=1001 (duplicate ACK)
8 0.320 10.0.0.15 → 10.0.0.5 TCP Seq=1001 Len=1000 (retransmission)
Your task: Deliver three things: (1) the packet number of the lost segment, (2) which packet proves it was lost (not just delayed), and (3) one sentence: should this app have used UDP instead — and why?
Workspace: Analyze-and-answer — type your three answers below, then check the commitment box to reveal the worked answer.
Hint 1 — where to look
The Info column's sequence numbers are the whole story. Line the packets up in order and watch the byte counters, not the timestamps.Hint 2 — what to compare
Each data packet's Seq says which bytes it carries; each ACK says which byte the server still needs. Find the bytes nobody ever acknowledges — then find the ACK that repeats a number you've already seen.Hint 3 — the mechanism
The receiver always acknowledges the next byte it still needs. A repeated ACK arriving after newer bytes got through means "I received the later piece, but the earlier one never showed up" — that is the proof of loss.☐ I've attempted this challenge and thought it through. (Checking reveals the worked answer in S7 — honor system: the page hides it until you commit.)
Checking the box reveals the worked answer in S7 below. Returning learners stay unlocked.
The handshake: agreeing before speaking
Before any important exchange, the two computers perform the three-way handshake (a three-packet greeting in which both sides agree on the rules before sending data). It works like this:
- The client sends SYN (short for synchronize — "I want to talk, and I'll number my bytes starting from 0").
- The server replies SYN-ACK — the ACK (short for acknowledgment — "message received") confirms the client's SYN, and the server's own SYN says "I'll number my bytes starting from 0 too."
- The client sends a final ACK — "deal." The conversation is now open.
Why bother? Because everything after this depends on numbering. Each side announces its starting sequence number (a running counter stamped on every piece, saying "these are bytes N through M"), and each reply carries an acknowledgment number (saying "I've received everything up to this point — send me the next byte"). The handshake synchronizes both counters so that later, a missing piece is instantly visible as a gap in the numbers.
Why this matters for the challenge: packets 1–3 of the capture are this exact ritual — and the numbers agreed there are what let you spot the missing piece later.
TCP: the registered letter
TCP (the Transmission Control Protocol — the registered letter of networking: every piece tracked, every delivery confirmed) gives you three guarantees: every byte arrives, arrives exactly once, and arrives in order. The machinery behind the guarantees:
- Numbering: every byte is counted (the sequence numbers from the handshake), so the receiver can spot gaps and duplicates.
- Acknowledgments: the receiver constantly reports the next byte it still needs. Silence means "something's missing."
- Retransmission (re-sending a piece the receiver never confirmed): if a piece vanishes, the sender simply sends those exact bytes again — same sequence numbers, second attempt.
The price: memory and patience. Both sides must remember the conversation — what's been sent, what's been confirmed — and a lost piece pauses everything behind it until the resend arrives. That remembered state is why TCP is called connection-oriented: the "connection" is the shared memory of the conversation.
Why this matters for the challenge: the stall the admin saw was this machinery working — a lost piece, a pause, a resend. The numbers tell you exactly which piece.
UDP: the postcard
UDP (the User Datagram Protocol — the postcard: fast, cheap, no tracking) makes the opposite trade. Each message is a datagram (one standalone message, independent of all others): the sender fires it off and moves on. No handshake, no numbering, no acknowledgments, no resends. If it arrives, great; if not, nobody is told.
What you lose: reliability, ordering, and any notion of a conversation — each datagram stands alone, which is why UDP is called stateless (no memory of past messages), versus TCP's stateful (both sides remember). What you gain: speed and simplicity. No three-packet greeting, no waiting for confirmations, no head-of-line blocking behind a lost piece.
Why this matters for the challenge: part 3 asks whether the postcard would have served this download better — you'll judge that trade with this section fresh in mind.
How the receiver keeps score
The scoreboard is just two numbers, and reading them is the single most useful capture skill in this lesson:
- Seq on a data packet = "these are bytes N through N+length."
- Ack on a reply = "I've got everything before byte N — send me byte N next."
Walk a healthy exchange: sender transmits bytes 1–1000 (Seq=1, Len=1000); receiver replies Ack=1001 ("got them, need 1001 next"). Sender transmits bytes 1001–2000; receiver replies Ack=2001. Now the failure mode: bytes 1001–2000 vanish, but bytes 2001–3000 arrive. The receiver can't acknowledge 3001 — it's still missing 1001 — so it repeats Ack=1001. That repeated number is a duplicate ACK (an acknowledgment restating a number it already sent, meaning "I'm still waiting on the same bytes"). One duplicate ACK says "a piece is missing"; the sender's response is a retransmission of exactly those bytes — recognizable because the Seq numbers match the original.
Why this matters for the challenge: this is the entire part-2 argument — the duplicate ACK is the proof, and now you know what it's proving.
Ports: which program gets the message
Addresses get data to the right machine; ports (numbers identifying which program on that machine should receive the data — the apartment numbers from Lesson 1.2) get it to the right program. A few you'll see constantly:
| Port | Program | Delivery style |
|---|---|---|
| 80 | Web (unencrypted) | TCP |
| 443 | Web (encrypted) | TCP |
| 53 | Name lookups (DNS) | UDP (mostly) |
| 22 | Remote login (SSH) | TCP |
| 25 | Email sending (SMTP) | TCP |
Notice the pattern: anything where a missing byte corrupts the result (web pages, logins, email) uses TCP; the name lookup — one tiny question, one tiny answer, asked millions of times a second — uses UDP, because re-asking is cheaper than handshaking.
Why this matters for the challenge: the file server's port and TCP go together for a reason — you'll state that reason in your one sentence.
Choosing: web, voice, video, DNS
The decision rule, plainly: if a gap in the data ruins the result, use TCP; if waiting for a resend ruins the result, use UDP.
- Web pages, file downloads, email: every byte matters and order matters — TCP.
- Live voice and video calls: a 200-millisecond pause for a resend is worse than a tiny glitch — UDP, and the app hides the gaps.
- Name lookups (DNS): one question, one answer; if it's lost, just ask again — UDP.
- Online games: positions update 60 times a second; stale resends are useless — UDP.
Neither is "better." The registered letter and the postcard are different tools, and the mark of an engineer is reaching for the right one without hesitation.
Why this matters for the challenge: your part-3 sentence is just this rule applied to a file download.
- Step 1 of 5: The client sends SYN: "I want to talk, and I'll number my bytes starting from 0."
- Step 2 of 5: The server replies SYN-ACK: "Message received — and I'll number my bytes from 0 as well."
- Step 3 of 5: The client sends the final ACK: "Deal." The connection is open — both sides agreed on the counting rules.
- Step 4 of 5: Numbered data flows; every reply names the next byte still needed.
- Step 5 of 5: If a piece vanishes, the numbers expose the gap — the sender resends exactly the missing bytes.
A full conversation: handshake, data, a hiccup, goodbye
green = healthy/expected · red = problem packet(s) · amber = noteworthy, not faulty · untinted = context
| No | Time | Source | Destination | Protocol | Length | Info |
|---|---|---|---|---|---|---|
| 1 | 0.000 | 10.0.0.15 | 10.0.0.5 | TCP | 66 | [SYN] Seq=0 |
| 2 | 0.050 | 10.0.0.5 | 10.0.0.15 | TCP | 66 | [SYN, ACK] Seq=0 Ack=1 |
| 3 | 0.051 | 10.0.0.15 | 10.0.0.5 | TCP | 60 | [ACK] Seq=1 Ack=1 |
| 4 | 1.200 | 10.0.0.15 | 10.0.0.5 | TCP | 1060 | Seq=1 Len=1000 (bytes 1–1000) |
| 5 | 1.450 | 10.0.0.15 | 10.0.0.5 | TCP | 1060 | Seq=1 Len=1000 [TCP Retransmission] |
| 6 | 5.000 | 10.0.0.15 | 10.0.0.5 | TCP | 60 | [FIN, ACK] Seq=1001 Ack=1 |
| 7 | 5.002 | 10.0.0.5 | 10.0.0.15 | TCP | 60 | [FIN, ACK] Seq=1 Ack=1002 |
| 8 | 5.003 | 10.0.0.15 | 10.0.0.5 | TCP | 54 | [ACK] Seq=1002 Ack=2 |
Step 1 of 3 · packets 1, 2, 3: The three-way handshake, exactly as the animation showed: SYN, SYN-ACK, ACK. Watch the Seq and Ack columns — the two sides agreeing on their counters.
Step 2 of 3 · packets 4, 5: Data flows (packet 4), then the same bytes appear again (packet 5, red). Compare the Seq fields: identical numbers mean identical bytes — a retransmission, the sender's repair job.
Step 3 of 3 · packets 6, 7, 8: The polite goodbye: each side sends FIN ('I'm done'), each FIN gets an ACK. A connection that opened with three packets closes with up to four.
| No | Time | Source | Destination | Protocol | Length | Info |
|---|---|---|---|---|---|---|
| 1 | 0.000 | 10.0.0.15 | 10.0.0.5 | TCP | 66 | [SYN] Seq=0 |
| 2 | 0.050 | 10.0.0.5 | 10.0.0.15 | TCP | 66 | [SYN, ACK] Seq=0 Ack=1 |
| 3 | 0.051 | 10.0.0.15 | 10.0.0.5 | TCP | 60 | [ACK] Seq=1 Ack=1 |
| 4 | 1.200 | 10.0.0.15 | 10.0.0.5 | TCP | 1060 | Seq=1 Len=1000 (bytes 1–1000) |
| 5 | 1.450 | 10.0.0.15 | 10.0.0.5 | TCP | 1060 | Seq=1 Len=1000 [TCP Retransmission] |
| 6 | 5.000 | 10.0.0.15 | 10.0.0.5 | TCP | 60 | [FIN, ACK] Seq=1001 Ack=1 |
| 7 | 5.002 | 10.0.0.5 | 10.0.0.15 | TCP | 60 | [FIN, ACK] Seq=1 Ack=1002 |
| 8 | 5.003 | 10.0.0.15 | 10.0.0.5 | TCP | 54 | [ACK] Seq=1002 Ack=2 |
Fixture: hand-authored to show a complete TCP conversation including one retransmission and a clean teardown; no production data
🔒 Revealed after the commitment ritual in S2 — attempt the challenge first. (Honor system: the page hides this until you check the box.)
Read the scoreboard, packet by packet.
(1) The lost segment is packet 5. Packets 1–3 are the handshake (Seq and Ack counters agreed). Packet 4 carries bytes 1–1000. Packet 5 carries bytes 1001–2000 — and those bytes are never acknowledged. Packet 6 carries bytes 2001–3000 and does get a reaction (packet 7), but packet 7's Ack number is 1001 — the server is still asking for byte 1001, the exact bytes packet 5 was carrying. So packet 5's original transmission vanished.
(2) Packet 7 proves it was lost, not delayed. A duplicate ACK is the server saying "I got something newer, but I'm still missing the older piece." The key: packet 6 (bytes 2001–3000, sent after packet 5) demonstrably arrived — the server reacted to it. If packet 5 were merely delayed in the same queue, it would have arrived before packet 6, not gone missing after newer bytes got through. Newer bytes arriving while older bytes stay missing is the signature of loss. The sender agrees with this verdict: packet 8 resends exactly bytes 1001–2000 (same Seq as packet 5 — the giveaway of a retransmission).
(3) No — UDP would be the wrong choice. One sentence: this is a file download, and a file with a hole in it is a corrupt file — only the registered letter's guaranteed, in-order delivery fits; the postcard's "maybe it arrives" would leave the download broken.
Wrong turns, named. You might have blamed packet 6 — it looks skipped, but it arrived just fine; it's packet 5's absence at the server that matters, not packet 6's presence. You might have picked packet 8 as the proof — but packet 8 is the response to the proof; the proof is the duplicate ACK in packet 7, which is what told the sender to resend. You might have blamed the server — but the server behaved perfectly: it acknowledged what it got and honestly reported what it was missing. And "why not UDP for speed?" — speed you can't trust is worthless for a file; the 0.3-second stall was TCP repairing the transfer, not failing it.
Verify it worked: re-run the download and compare checksums (e.g. the file's hash before and after) — they must match; in a fresh capture, ACK numbers advance steadily (1001 → 2001 → 3001) with no repeated numbers and no retransmissions.
Check yourself — nothing here is graded. Wrong answers are the useful ones; each explains why.
Question 1. A receiver sends back Ack=1001. What does that number mean?
Question 2. You're building a live voice-call app. A 200 ms pause ruins the call, but nobody notices a 20 ms glitch. TCP or UDP — and why?
Question 3. Put the three-way handshake in order:
Question 4. In a capture you see two packets from the same sender with identical sequence numbers and lengths. What happened?
Question 5. A web page loads half its images, then stalls for a few seconds, then finishes. A capture shows the server sending the same ACK number five times in a row. What is happening, and what should you do?
- The three-way handshake (SYN → SYN-ACK → ACK) lets both sides agree on starting byte numbers before any data moves.
- Every ACK number names the next byte the receiver still needs — a repeated ACK means a piece went missing, not that data is flowing.
- A retransmission is recognizable by identical sequence numbers: the same bytes, sent twice.
- Choose TCP when every byte must arrive in order (files, web pages); choose UDP when waiting would hurt more than losing a piece (live voice, games, name lookups).
- Ports decide which program receives the data; the handshake decides the rules — addresses get it to the machine, ports and connections get it to the program.
Next: DNS: The Internet's Phone Book — You can now read the handshake that starts every web page load; next you'll meet the phone book that turns the name you typed into the address that handshake needs.