Introduction
Hello! In our last lesson, we examined the TCP three-way handshake, the formal process of establishing a connection. You learned how the SYN and ACK flags, along with initial sequence numbers (ISNs), get both the client and server into an ESTABLISHED state, ready for communication.
But establishing the connection is just the start. The true power of TCP lies in its promise of reliable delivery. How does TCP guarantee that a file, a webpage, or a message arrives completely and in the correct order, even across the an unreliable internet where packets can be lost, duplicated, or reordered?
This lesson will answer that question. We will build directly on your understanding of sequence and acknowledgment numbers to explore the core mechanisms TCP uses to provide reliability. By the end, you will be able to explain how TCP detects and recovers from packet loss, ensuring data integrity from sender to receiver.
1. From Counting Packets to Counting Bytes
In the three-way handshake, we saw that acknowledging a SYN packet involved incrementing the sequence number by one. This might suggest that TCP counts packets. However, this is a simplification for control packets. For actual data transfer, TCP operates on a more granular level.
TCP is a byte-stream protocol. It does not see data as a series of discrete packets, but as a continuous stream of bytes. The sequence number in a TCP segment refers to the position of the first byte of data in that segment within the entire stream.
Let's clarify this with a video.
TCP - 12 simple ideas to explain the Transmission Control Protocol
The video 'TCP - 12 simple ideas' from Practical Networking provides an excellent explanation of how sequence and acknowledgment numbers track bytes, not packets.
Watch the segment from 02:54 to 06:36. Focus on the core idea: the acknowledgment number sent by the receiver is calculated as sender's sequence number + number of bytes received.
As the video demonstrated, the rule is simple but powerful:
- Sequence Number (SEQ): The byte number of the first byte of data in the current segment.
- Acknowledgment Number (ACK): The sequence number of the next byte the receiver expects to get.
For example, if a PC sends a segment with Seq=1001 containing 1400 bytes of data, the data occupies bytes 1001 through 2400. The receiver, upon successful receipt, will send back a segment with Ack=2401.
This Ack=2401 serves two purposes:
- It confirms receipt of all bytes up to and including byte 2400. This is known as a cumulative acknowledgment.
- It tells the sender, "I am ready for the next chunk of data, and I expect it to start with byte 2401."
This byte-level accounting is the foundation of TCP's reliability.
For a concise textual reinforcement of this concept, let's turn to a chapter from a networking textbook.
Read the section '12.2 TCP Header'. Pay attention to the definitions of sequence and acknowledgment numbers and the explanation of cumulative acknowledgments.
2. Handling Loss: Timeouts and Retransmission
The internet is not perfect. Routers can get congested and drop packets. An acknowledgment might get lost on its way back to the sender. How does TCP handle this?
The primary mechanism is the retransmission timeout (RTO). Here’s how it works:
- Keep a Copy: When a sender transmits a TCP segment, it stores a copy of that segment in its memory.
- Start a Timer: It also starts a retransmission timer for that specific segment.
- Wait for ACK: The sender waits for an acknowledgment from the receiver that covers the data in that segment.
- Success or Failure:
- If the ACK arrives before the timer expires: Great! The sender knows the data was received. It can discard the copy and cancel the timer.
- If the timer expires before the ACK arrives: The sender assumes the segment (or its corresponding ACK) was lost. It then retransmits the segment from its stored copy and restarts the timer.
This process ensures that data is resent until its reception is confirmed.
TCP - 12 simple ideas to explain the Transmission Control Protocol
Let's return to the 'TCP - 12 simple ideas' video, which provides a clear animation of this timeout and retransmission process.
Watch the segment from 06:36 to 09:41. Notice how this mechanism works whether the data segment is lost or the acknowledgment segment is lost. Also, pay attention to how the receiver uses sequence numbers to handle duplicate packets.
The video highlights a critical point: sequence numbers are essential for identifying duplicates. If an ACK is lost, the sender will retransmit. The receiver will get the same data twice. By checking the sequence number, the receiver recognizes it has already processed this data, discards the duplicate segment, and simply re-sends the same acknowledgment.
3. A Complete Data Exchange
Let's trace a sample conversation to see how these numbers flow back and forth. The table below shows a connection from establishment to data transfer, using relative sequence numbers for simplicity.
- The client (A) has an ISN of 1000.
- The server (B) has an ISN of 7000.
| Step | A (Client) Sends | B (Server) Sends | Explanation |
|---|---|---|---|
| 1 | SYN, Seq=1000 |
Client initiates connection. | |
| 2 | SYN, ACK, Seq=7000, Ack=1001 |
Server acknowledges SYN (1000+1) and sends its own SYN. |
|
| 3 | ACK, Seq=1001, Ack=7001 |
Client acknowledges server's SYN (7000+1). Connection is established. |
|
| 4 | DATA ("abc"), Seq=1001, Ack=7001, Len=3 |
Client sends 3 bytes of data. The sequence number is 1001, as expected. | |
| 5 | ACK, Seq=7001, Ack=1004 |
Server acknowledges the 3 bytes (1001+3). |
|
| 6 | DATA ("defg"), Seq=1004, Ack=7001, Len=4 |
Client sends the next 4 bytes, starting from the last acknowledged byte (1004). | |
| 7 | ACK, Seq=7001, Ack=1008 |
Server acknowledges the next 4 bytes (1004+4). |
|
| 8 | DATA ("hello"), Seq=7001, Ack=1008, Len=5 |
Server sends 5 bytes of its own data. | |
| 9 | ACK, Seq=1008, Ack=7006 |
Client acknowledges the server's 5 bytes (7001+5). |
This step-by-step flow shows the beautiful symmetry of TCP. Each side independently tracks the bytes it sends (with Seq) and the bytes it has received from the other side (with Ack).

4. Visualizing Packet Loss and Recovery
A space-time diagram can be a powerful tool for visualizing the back-and-forth of a TCP session and the impact of packet loss.

Let's trace the events in this diagram:
- Sender sends a segment with
Seq=1and 1000 bytes of data. - Receiver gets the segment and sends back
Ack=1001. - Sender receives the ACK and immediately sends the next segment,
Seq=1001, also with 1000 bytes. - This segment is lost! It never arrives at the receiver.
- The Sender's retransmission timer for the
Seq=1001segment continues to tick. - Timeout! The timer expires. The sender, having received no
Ack=2001, assumes the packet was lost. - Sender retransmits the lost segment, again with
Seq=1001. - This time, the segment arrives. The Receiver processes it and sends back
Ack=2001. - The connection is now back on track.
This simple loop—send, start timer, retransmit on timeout—is the fundamental algorithm that makes TCP a reliable protocol.
Conclusion
In this lesson, we've gone under the hood of TCP to see how it achieves its famous reliability. You've seen that the sequence and acknowledgment numbers established during the handshake are the critical tools for a robust data transfer process.
Key Takeaways:
- TCP is a byte-stream protocol; sequence numbers track individual bytes, not packets.
- The acknowledgment number is cumulative:
Ack=Nconfirms receipt of all data up to byteN-1. - The key formula is:
Acknowledgment Number = Sequence Number + Bytes Sent. - TCP detects packet loss using a retransmission timeout (RTO). If an ACK isn't received before the timer expires, the segment is resent.
- Sequence numbers allow the receiver to discard duplicate packets and reassemble segments that may have arrived out of order.
Preview of the Next Lesson:
We've established that TCP can ensure data gets to the receiver reliably. But what if the sender transmits data much faster than the receiver can process it? This would overwhelm the receiver's buffer, leading to dropped packets and inefficient retransmissions.
In the next lesson, we will explore TCP Flow Control, the mechanism TCP uses to prevent this. You'll learn about the "sliding window," a clever technique that allows the receiver to tell the sender exactly how much data it's prepared to accept at any given moment.