RFC 9293 (the current TCP specification, 2022), RFC 5681 (ACK generation and fast retransmit) and RFC 6298 (the retransmission timer), cross-checked against Kurose and Ross, section 3.5. Every sequence and ACK number in the examples was traced by hand and checked in code.
Learn the two rules in the sequence-number section until you can say them without looking. Then trace every example yourself on paper, writing the Seq and ACK on each arrow. If your numbers match, the rest of the topic follows.
Course slides often cite RFC 793 for TCP and RFC 2581 for the ACK rules. Both have been replaced: TCP is now specified in RFC 9293 (2022) and congestion control, including fast retransmit, in RFC 5681. Nothing on this page changes because of that; the behavior tested in a first networking course is the same.
The picture: numbering the pages of a book you mail in parts#
You are mailing a 500-page manuscript in several envelopes. You number every page, not every envelope. The envelope that starts at page 201 is “envelope 201”. Your editor replies with a postcard that says “next, I need page 301”, which tells you everything up to 300 arrived.
TCP works exactly like that, except it numbers bytes, not pages. That one idea explains both the sequence number and the ACK number.
Vocabulary, before anything uses it#
| Term | What it means |
|---|---|
| Segment | The transport-layer packet: a TCP header plus a chunk of data. |
| Byte stream | TCP treats the data as one long, ordered stream of bytes, numbered in order. |
| MSS | Maximum segment size: the most application data one segment may carry (not counting headers). |
| Sequence number | The byte-stream number of the first data byte in the segment. |
| ACK number | The number of the next byte the receiver expects from the other side. |
| Cumulative ACK | An ACK number n means every byte before n has arrived. |
| Piggybacking | Carrying an ACK inside a segment that is also carrying data in the other direction. |
| Duplicate ACK | An ACK that repeats an ACK number the sender has already received. |
| Timeout | The retransmission timer running out before the ACK arrives. |
The TCP segment, field by field#
0 16 31 (bits)
+-------------------+-------------------+
| source port | dest port |
+-------------------+-------------------+
| sequence number |
+---------------------------------------+
| acknowledgment number |
+------+------+-----+-------------------+
|hdr len|unused|flags| receive window |
+------+------+-----+-------------------+
| checksum | urgent pointer |
+-------------------+-------------------+
| options (variable length) |
+---------------------------------------+
| application data ... |
+---------------------------------------+| Field | Size | Purpose |
|---|---|---|
| Source and destination port | 16 bits each | Multiplexing and demultiplexing, same as UDP. |
| Sequence number | 32 bits | Byte number of the first data byte in this segment. |
| Acknowledgment number | 32 bits | Next byte expected from the other side. Valid when the ACK flag is set. |
| Header length | 4 bits | Header size in 32-bit words. Usually 5, meaning 20 bytes. |
| Flags | 1 bit each | SYN and FIN open and close connections, ACK says the ACK number is valid, RST resets a connection, PSH asks for data to be passed up now, URG marks urgent data. Newer headers also carry two congestion-notification flags (CWR and ECE). |
| Receive window | 16 bits | How many bytes the receiver is willing to accept. Used for flow control. |
| Checksum | 16 bits | Error detection, computed like UDP's. |
| Urgent data pointer | 16 bits | Where the urgent data ends. Rarely used. |
| Options | 0 to 40 bytes | For example, the MSS each side can accept. |
A TCP header is 20 bytes without options and at most 60. UDP's is 8. Header length counts in 4-byte words, so the largest value, 15, means 60 bytes.
Sequence numbers and ACK numbers: the two rules#
Everything in this topic comes from two rules:
Sequence number = number of the first byte in this segment
ACK number = number of the next byte I expect from you
Example: splitting a file. A 500,000-byte file is sent with an MSS of 1,000 bytes, and the first byte is numbered 0. That makes 500 segments. Their sequence numbers are 0, 1,000, 2,000, and so on. (Real connections start from a random number, chosen during the handshake, but the counting works the same.)
Example: a typed character echoed back. A client types the letter k to a server that echoes it back. Suppose the client's next byte to send is numbered 100 and the server's is 300.
| Segment | Seq | ACK | Data | Why |
|---|---|---|---|---|
| 1. Client → server | 100 | 300 | k | Client sends byte 100 and says it expects the server's byte 300 next. |
| 2. Server → client | 300 | 101 | k | Server ACKs byte 100 (“next I want 101”) and echoes k. The ACK is piggybacked on data. |
| 3. Client → server | 101 | 301 | none | Client ACKs the echo. No data, but it still carries its next sequence number. |
Because ACKs are cumulative, ACK 301 means every byte up to 300 arrived, not just one byte.
The ACK is not the number of the byte you received. It is one past it. Receiving bytes 247 to 286 produces ACK 287. Writing 286 is the single most common mistake in TCP questions.
Each direction has its own numbering. The client's sequence numbers and the server's sequence numbers are completely separate streams.
Worked example: two segments, one lost#
Host A has just sent two segments back to back to host B. The first has sequence number 247 and carries 40 bytes. The second carries 60 bytes. (a) What is the second segment's sequence number? (b) If both arrive in order, what ACK number does B send for each? (c) If the first is lost and the second arrives, what ACK number does B send?
(a) The first segment holds bytes 247 to 286. The next byte is 287.
247 + 40 = 287
(b) After the first, B wants byte 287: ACK 287. After the second, which holds bytes 287 to 346: ACK 347.
(c) B is still waiting for byte 247. The segment that arrived starts at 287, which is out of order. B must still say what it needs next: ACK 247. If B has already sent ACK 247 before (the usual case), this is a duplicate ACK: it repeats an ACK number the sender has already seen. (B will usually buffer the out-of-order segment, so it does not have to be sent twice.)
The byte range of each segment written out, the ACK stated as the next byte expected, and for (c) the observation that the ACK does not move past a gap.
TCP's sender, and the three retransmission scenarios#
A TCP sender reacts to three events:
| Event | What the sender does |
|---|---|
| Data arrives from the application | Make a segment with the next sequence number. If the timer is not already running, start it. |
| Timeout | Retransmit the oldest unacknowledged segment, and restart the timer. |
| ACK arrives | If it acknowledges new data, move the “oldest unACKed” point forward. If data is still unacknowledged, restart the timer. |
TCP uses a single timer for the oldest unACKed segment, not one per segment. The timeout length is based on measured round-trip times, and after each timeout TCP doubles it, so a congested network is not flooded with retransmissions.
Three scenarios come up again and again. In all three, A sends to B, and segments carry 100 bytes.
1. Lost ACK
A sends Seq 500. B receives it and sends ACK 600, which is lost. A's timer runs out, so A retransmits Seq 500. B already has those bytes: it throws the copy away and sends ACK 600 again.
2. Premature timeout
A sends Seq 500 and Seq 600. B sends ACK 600 and ACK 700, but both are slow, and A's timer runs out first. A retransmits only Seq 500, the oldest unACKed segment, and restarts the timer. The delayed ACKs then arrive, ACK 700 among them, so A does not resend Seq 600. B discards the duplicate 500 and replies ACK 700.
3. A cumulative ACK saves the day
A sends Seq 500 and Seq 600. ACK 600 is lost, but ACK 700 arrives before the timer runs out. Because ACKs are cumulative, ACK 700 says bytes up to 699 all arrived. A retransmits nothing.
A lost ACK is fixed by the timer. A late ACK causes a harmless duplicate. A later ACK covers for a lost earlier one.
When the receiver sends an ACK#
| Event at the receiver | What the receiver does |
|---|---|
| In-order segment arrives; everything before it already ACKed | Delayed ACK: wait a short time (up to 500 ms) for another segment, then ACK. Saves sending an ACK for every segment. |
| In-order segment arrives; another in-order segment is waiting for its delayed ACK | Send one cumulative ACK at once, covering both. |
| Out-of-order segment arrives: a gap is detected | Send a duplicate ACK at once, naming the next byte expected (the start of the gap). |
| A segment arrives that fills all or part of a gap | ACK at once, if the segment starts at the lower end of the gap. |
Fast retransmit: three duplicate ACKs#
Timeouts are slow, often far longer than one round trip. But duplicate ACKs give the sender an early warning. If one segment is lost and later ones get through, each later one produces a duplicate ACK for the missing byte.
The rule: if the sender receives three duplicate ACKs for the same data, it retransmits the missing segment right away, without waiting for the timer.
A sends five 100-byte segments: Seq 500, 600, 700, 800, 900. Seq 600 is lost.
| At B | B sends | Meaning |
|---|---|---|
| Seq 500 arrives | ACK 600 | First ACK for 600 (normal) |
| Seq 700 arrives (gap) | ACK 600 | 1st duplicate |
| Seq 800 arrives | ACK 600 | 2nd duplicate |
| Seq 900 arrives | ACK 600 | 3rd duplicate: A retransmits Seq 600 now |
| Seq 600 arrives | ACK 1000 | The gap is filled. B had buffered 700 to 999, so one cumulative ACK covers everything |
“Three duplicate ACKs” means four ACKs with the same number in total: the original ACK plus three duplicates. Retransmitting after the first duplicate is too early, because a little reordering in the network is normal.
The sequence number is the first byte in the segment, the ACK number is the next byte wanted, ACKs are cumulative, and TCP retransmits the oldest unACKed segment on a timeout or on three duplicate ACKs.
Practice#
Draw a timeline with A on the left, B on the right, and label every arrow with its Seq or ACK. It takes longer and it is the only reliable way.
- What is the minimum size of a TCP header, and what does a header length field of 5 mean?
- Which TCP header fields are also in the UDP header, and which field is used for flow control?
- A 1,200,000-byte file is sent with an MSS of 1,500 bytes, first byte numbered 0. How many segments are there, and what is the sequence number of the fourth one?
- B has received all bytes up to and including 1,999. What ACK number does it send?
- A sends two segments: Seq 90 with 20 bytes, then another with 30 bytes. Give the second segment's sequence number and the ACK B sends after receiving both in order.
- In question 5, the first segment is lost and the second arrives. What ACK does B send?
- On a timeout, which segment does TCP retransmit?
- A sends Seq 500 and Seq 600 (100 bytes each). ACK 600 is lost; ACK 700 arrives before the timeout. What does A retransmit?
- How many ACKs carrying the same number must a sender see before fast retransmit, and why not act on the first duplicate?
Solutions#
Find the first line where your working split from the solution, and redo the problem from that line. Do not just read the answer and nod.
- 20 bytes; 5 words of 4 bytes. The header length counts 32-bit (4-byte) words, so 5 means 5 × 4 = 20 bytes, a header with no options.
- Source port, destination port and checksum; receive window. Those three match UDP (which also has a length field). The receive window carries flow-control information.
- 800 segments; 4,500. 1,200,000 / 1,500 = 800. Sequence numbers go 0, 1,500, 3,000, 4,500, so the fourth is 4,500.
- 2,000. The ACK is the next byte expected, one past the last byte received.
- Seq 110; ACK 140. The first holds bytes 90 to 109, so the second starts at 110. It holds 110 to 139, so after both, B wants 140.
- ACK 90. B still needs byte 90. The segment starting at 110 is out of order, so B sends a duplicate ACK for 90.
- The oldest unacknowledged segment. TCP keeps one timer for the oldest unACKed segment and retransmits only that one when it expires.
- Nothing. ACK 700 is cumulative: it confirms every byte up to 699, so both segments are known to have arrived.
- Four in total: the original plus three duplicates. A single duplicate can be caused by segments simply arriving out of order. Three duplicates make loss much more likely than reordering.
Test-readiness checklist#
- ☐ I can draw the TCP header and state the purpose of every field.
- ☐ I can state the minimum and maximum header size and read the header length field.
- ☐ I can define sequence number and ACK number and apply both rules.
- ☐ I can split a file into segments and give their sequence numbers.
- ☐ I can trace a piggybacked ACK exchange.
- ☐ I can explain the lost-ACK, premature-timeout and cumulative-ACK scenarios.
- ☐ I can state the receiver's four ACK-generation rules.
- ☐ I can trace fast retransmit and say how many ACKs trigger it.
Write the byte range for each segment, such as “bytes 287 to 346”, before you write any ACK number. The ACK is then simply the last byte plus one, and the off-by-one error cannot happen.
Frequently asked questions#
What is the difference between the TCP sequence number and the acknowledgment number?
The sequence number is the byte-stream number of the first data byte in the segment. The acknowledgment number is the number of the next byte the sender of the ACK expects to receive from the other side.
Why are TCP ACKs called cumulative?
An ACK number n means every byte up to n minus 1 has been received. So a later ACK confirms everything before it, and a lost earlier ACK does not force a retransmission if a later ACK arrives in time.
What is TCP fast retransmit?
When the sender receives three duplicate ACKs for the same data, meaning four ACKs with the same number in total, it assumes the segment after the acknowledged data was lost and retransmits it immediately, without waiting for the timeout.
How big is the TCP header?
20 bytes without options and up to 60 bytes with options. The 4-bit header length field gives the size in 32-bit words, so the usual value 5 means 20 bytes.
Which segment does TCP retransmit on a timeout?
Only the oldest segment that has not yet been acknowledged. TCP then restarts the timer, and after each timeout it doubles the timeout interval.
Something here not clear? A topic you wish we covered? Tell us. We read every message, and a request is the fastest way to get a guide written.
Test yourself on this topic
The free networking practice app has 19 questions on this topic and 500 across the whole course, each with an explanation for every answer. Offline, no ads, no account.
Practise this topic →