Two numbers on every segment
Every TCP segment carries a sequence number (SEQ) and an acknowledgement number (ACK). Together they let both sides track exactly which bytes have been sent and which have safely arrived.
SEQ · "this is where I am"
The number of the first byte of data in this segment.
ACK · "this is what I want next"
The number of the next byte the sender of this segment expects from the other side.
Each direction has its own count. The laptop numbers the bytes it sends to kade-api; kade-api numbers the bytes it sends back. Every segment says both "here are my bytes from N" (SEQ) and "I have yours up to M − 1" (ACK).
Numbers start at random
Numbers do not start at 0. During the handshake each side picks a random Initial Sequence Number (ISN), a 32-bit number. The SYN in chapter 18 really starts at 2,591,834,610.
- Security: an attacker who is not on the path would have to guess the current numbers to inject fake data or reset the connection. A random start makes that very hard.
- Safety: a new connection on the same ports will not accept stray packets from an old one, because the old numbers are far away from the new ones.
SEQ counts bytes, not segments
This is the subtle, important part. If a segment carries bytes 1-50, its SEQ is 1. The next segment, carrying bytes 51-100, has SEQ = 51, not 2. The SEQ is simply the number of the first byte in that segment.
the laptop's 150-byte request to kade-api, cut into three 50-byte segments (small, to keep the numbers easy)
ACK names the next byte expected
If kade-api has received bytes 1-50, it replies ACK = 51. That means: "I have everything up to byte 50. Send me byte 51 next." The ACK never lists what arrived; it names the first gap.
The numbers in the handshake
You can watch the counting start in the handshake itself. Say the laptop picks ISN x = 4000 and kade-api picks y = 9000:
| Segment | SEQ | ACK | Why |
|---|---|---|---|
| SYN | x = 4000 | - | The laptop's random start |
| SYN-ACK | y = 9000 | x + 1 = 4001 | The SYN uses up one number, even with no data, so the next expected is 4001 |
| ACK | x + 1 = 4001 | y + 1 = 9001 | Same for kade-api's SYN |
| First data | 4001 | 9001 | The first real byte from the laptop is number 4001 |
Losses and how they are repaired
Reliability falls out of these two numbers. If a segment is lost, no ACK for it comes back, and because ACKs name the next expected byte, the sender knows exactly what to resend. The laptop sends five 100-byte segments. Pick what goes wrong:
The receiver ACKs every second segment. Each ACK is cumulative: ACK 4201 confirms bytes 4001–4200 at once. 5 segments, only 3 ACKs.
Two ways to notice a loss
| Retransmission timeout | Fast retransmit | |
|---|---|---|
| Trigger | No ACK for a segment before a timer runs out | 3 duplicate ACKs in a row |
| How fast | Slow: the timer (RTO) is based on measured round-trip time, at least 200 ms on Linux, and doubles after each miss | Fast: about one round trip after the loss |
| When it is needed | The lost segment was the last one, so nothing follows to cause duplicate ACKs | More data keeps flowing after the lost segment |
| After it | Congestion window drops hard (chapter 16) | Congestion window is cut, less sharply |
While waiting for the missing segment, the receiver keeps the later ones in a buffer. It cannot hand them to the app yet, because TCP promises order. This waiting is the head-of-line blocking from chapter 14.
Cumulative and delayed ACKs
ACKs are cumulative: one ACK = 4501 confirms every byte up to 4500 at once, not just one segment. This keeps overhead low. Receivers also use delayed ACK: instead of answering every segment, they usually ACK every second segment, or after a short wait (up to about 40 ms on Linux). Both appear in the "Normal" case of the simulator.
ACKs also ride on data going the other way (piggybacking). When kade-api sends its response, the same segments carry its ACK for the laptop's request, so no separate ACK is needed.
When the numbers run out
SEQ is 32 bits, so it wraps back to 0 after 4,294,967,295 bytes (about 4 GB). That is fine: comparisons are done "around the circle". On very fast links, 4 GB can pass in a few seconds, so TCP adds a timestamp option to each segment to tell an old, wrapped-around segment from a new one.
Summary
| # | Idea | In one line | New terms |
|---|---|---|---|
| 1 | Two numbers | SEQ = my first byte here; ACK = your next byte I expect | SEQ, ACK |
| 2 | Random start | Each side picks a random ISN; tools show relative numbers | ISN |
| 3 | Bytes | Next SEQ = SEQ + data length | |
| 5 | Handshake | SYN and FIN use one number each: ACK = x + 1 | |
| 6-7 | Losses | Timeout or 3 duplicate ACKs → resend exactly the missing bytes | RTO, duplicate ACK, fast retransmit, SACK |
| 8 | Low overhead | Cumulative, delayed and piggybacked ACKs | delayed ACK, piggybacking |
| 9 | Wraparound | 32-bit numbers wrap after ~4 GB; timestamps help |
Try it yourself
A real conversation
- Steps:
sudo tcpdump -n -i en0 host example.com, thencurl -s http://example.com > /dev/null - What to look for:
seq 1:78= bytes 1 to 77 (78 is the next);ack 1235; the handshake with real random numbers. - From section: 5. The numbers in the handshake
sudo tcpdump -n -i en0 host example.comcurl -s http://example.com > /dev/nullThe same, with absolute numbers
- What to look for: Big 10-digit numbers everywhere.
- From section: 2. Numbers start at random
sudo tcpdump -S -n -i en0 host example.comLive TCP details per connection
- What to look for:
rtt,rto,retrans,cwnd. - Runs on: Linux
- From section: 7. Two ways to notice a loss
ss -tiRetransmission counters
- What to look for: Fast retransmits vs timeouts since boot.
- From section: 7. Two ways to notice a loss
netstat -s | grep -i retransProblems Wireshark detected
- Steps: Wireshark:
tcp.analysis.flagsas a filter - What to look for: "Duplicate ACK", "Retransmission", "Out-Of-Order" labels.
- From section: 6. Losses and how they are repaired
tcp.analysis.flags