Week 8 · Lesson 5

TCP Connection Management

Lesson 4 opened the connection with a handshake. This lesson is about the rest of the story: how the two ends keep track of every byte with sequence and acknowledgment numbers, what happens when a segment is lost, how the connection is closed politely with FIN, how it is torn down in the middle with RST, and why the closing side lingers in TIME_WAIT before letting go.

CCNA 200-301 Domain 1.4 & 5.0 Transport Verified 2026-10-11
Part 1

Tracking the conversation

TCP is a byte-stream protocol. The application hands TCP an unstructured stream of bytes, and TCP slices it into segments. The receiver must be able to put those segments back in order and to notice a gap if one is missing. It does this with two numbers carried in every segment (both are in the TCP header, which Lesson 6 dissects):

Definition — cumulative acknowledgment The acknowledgment number is the next byte expected. One number therefore confirms every byte up to (but not including) that point — which is why TCP acknowledgments are called cumulative: a later ACK implicitly confirms all earlier data.

Both ends pick a random initial sequence number (ISN) at connection setup so that old, delayed segments from a previous connection cannot be mistaken for new data. Two segments consume one sequence number even though they carry no data: SYN and FIN. That is why the first data byte after a handshake where the client’s ISN was 1001 is 1002, not 1001.

Exam tip Remember the arithmetic: ACK = SEQ + length of the data received. A 100-byte segment with SEQ = 1 is acknowledged with ACK = 101. Also remember that SYN and FIN each consume one sequence number but carry no payload.
Session trace · step through the whole connection

      

Part 2

A worked example: bytes 1–100

For clarity, number the sender’s application bytes 1, 2, 3, … . The sender builds a segment with 100 bytes of payload and sends it:

! Sender sends the first 100 bytes of the stream
segment:  SEQ = 1   len = 100   (carries bytes 1 .. 100)

! Receiver has bytes 1..100 in order, so it expects byte 101 next
ACK:      ACK = 101             (next byte expected = 101)

If the sender then sends another 100 bytes, its sequence number is 101 and the receiver answers 201. The pair of numbers advances together, one for what was sent and one for what was received. The receiver can also piggyback its own data onto an acknowledgment: a segment can carry both an ACK field and a payload, so the two directions share the overhead.

Notice the receiver does not need to acknowledge each byte individually, nor even each segment. Real implementations often wait a short time (delayed ACK) or acknowledge every second segment, and one ACK can cover several segments at once. This is the efficiency of cumulative acknowledgment.

Part 3

Loss, timeout, and fast retransmit

IP can lose, duplicate, or reorder segments. TCP defends against loss with a retransmission timer:

  1. The sender transmits a segment and starts a timer.
  2. The receiver’s ACK arrives before the timer expires → the timer is cancelled and the next segment is sent.
  3. No ACK arrives before the timer expires → the sender assumes the segment (or its ACK) was lost and retransmits the same data with the same sequence number.

The timer value is adapted, not fixed. TCP measures the round-trip time (RTT) of live segments and computes a retransmission timeout (RTO) that tracks it, with extra margin. On a slow link the RTO grows; on a fast one it shrinks. After each failed retransmission the sender generally waits longer (an exponential back-off): 1 s, 2 s, 4 s, 8 s, and so on, up to a limit, before giving up if the application has not allowed TCP to keep trying.

Remember Retransmission is what makes TCP reliable. The network does not guarantee delivery; TCP notices the missing acknowledgment and sends again. A retransmitted byte may then arrive twice at the receiver, which drops the duplicate because its sequence number is below the next expected byte.

Duplicate ACKs and fast retransmit

Waiting for a timer is slow — the sender may sit idle for a full RTO. TCP has a faster signal. Suppose the receiver gets bytes 1–100, then bytes 201–300 (segment 101–200 was lost). For every out-of-order segment that arrives, the receiver sends the same acknowledgment it already sent: ACK = 101. A repeated acknowledgment that names data the receiver still lacks is a duplicate ACK.

When the sender sees a small number of duplicate ACKs (the classic threshold is three) all acknowledging the same byte, it concludes that a single segment was lost rather than that the network is congested or reordered, and it retransmits immediately without waiting for the timer. This is fast retransmit. (The closely related fast recovery mechanism then reduces the send rate rather than restarting from scratch.)

Exam tip Three duplicate ACKs → fast retransmit. No duplicate ACKs at all (for example the acknowledgment itself was lost) → the sender must wait out its retransmission timer. Both paths recover the same lost byte; the duplicate-ACK path is simply quicker.
Two ways to recover a lost segment · select one

Part 4

Connection termination: the FIN exchange

A TCP connection is full-duplex: data flows both ways, and each direction is an independent stream. Closing is therefore one direction at a time, not a single event. To close its half, an endpoint sends a segment with the FIN flag set, meaning “I have no more data to send.”

Because FIN is one-way, a complete graceful close takes four messages, often called the four-way teardown. The party that sends the first FIN is the active closer; the other is the passive closer.

     Active closer (client)                         Passive closer (server)
             |                                                 |
             |  1. FIN, SEQ = x            [no more data]      |   server may still send
             |------------------------------------------------>|
             |  2. ACK, ACK = x+1                              |   its own outstanding data
             |<------------------------------------------------|
             |                                                 |   ... server finishes ...
             |  3. FIN, SEQ = y                                |
             |<------------------------------------------------|
             |  4. ACK, ACK = y+1                              |
             |------------------------------------------------>|   both halves now closed

Read the phase numbers carefully. Phase 1 is the client’s FIN; phase 2 is the server’s ACK of that FIN. The client has stopped sending, but the server may not be done — it can keep sending data to the client, which is why the server votes separately. When the server is finished it sends its own FIN (phase 3), and the client acknowledges it (phase 4). FIN in each direction consumes one sequence number, so the acknowledgment is always one greater than the FIN’s sequence number.

Note — “FIN & ACK” vs “three-way close” If the passive closer has nothing left to send, it can set FIN and ACK together and collapse phases 2 and 3 into one segment, making the close look like three messages. Many tools and textbooks then speak of a “three-way close.” The canonical description is still four distinct phases; the combined form is an abbreviation. You may also see a single RST used instead of any of this (Part 5).

The four phases of teardown

PhaseMessageMeaning
1Active closer sends FIN“I will send no more data.” The send half is closing.
2Passive closer sends ACK“I have received your FIN.” Its receive half is closing.
3Passive closer sends FIN“I too am finished sending.” Now the second half closes.
4Active closer sends ACK“I have received your FIN.” The connection is fully closed.
The four teardown phases · select one

Part 5

TIME_WAIT and abnormal termination with RST

After sending the final ACK (phase 4), the active closer does not close immediately. It enters a state called TIME_WAIT and holds the connection open for a set period, conventionally twice the maximum segment lifetime (2×MSL) — on the order of one to four minutes in real systems. Two problems are solved by waiting:

Exam tip “Why does the closing side wait in TIME_WAIT?” Two answers: (1) to handle a retransmitted FIN if the final ACK was lost, and (2) to let delayed duplicate segments from the old connection expire so they cannot corrupt a new connection reusing the same ports. TIME_WAIT applies to the active closer.

You will see TIME_WAIT constantly when you run netstat on a busy web server: the server-side sockets linger after each short client connection. This is normal and desirable; operators tune the timeout only when a huge connection rate (for example behind a load balancer) exhausts the ephemeral port range.

! Illustrative only - exact columns vary by OS ("netstat -an" on Windows)
Proto  Local Address        Foreign Address      State
TCP    127.0.0.1:52413      127.0.0.1:80         TIME_WAIT
TCP    127.0.0.1:52414      127.0.0.1:80         ESTABLISHED
TCP    127.0.0.1:80         127.0.0.1:52414      ESTABLISHED

Abnormal termination with RST

Not every close is graceful. A segment with the RST (reset) flag set tears the connection down immediately and without negotiation. RST is the TCP equivalent of slamming the phone down; no FIN, no TIME_WAIT, no courtesy. Common causes:

When you see Connection reset by peer, the far end has sent a RST. When a tool reports Connection refused, the far end answered your SYN with RST because nothing was listening. A silent failure — a SYN that gets no answer at all — usually means a firewall dropped the packet rather than rejecting it.

Part 6

Open, half-open, and the session life cycle

Put the events of Lessons 4 and 5 into one life cycle. Along the way, two security-relevant terms appear:

Security note — the SYN flood A half-open connection is the raw material of the SYN flood attack. The attacker sends many SYNs but never completes the handshake, so the server allocates a half-open entry for each and exhausts its resources. Defences include SYN cookies and connection timeouts. This is why you must understand the handshake, not just the port numbers.
CLOSED Handshake SYN / SYN-ACK / ACK ESTABLISHED data + ACKs both ways FIN exchange FIN / ACK / FIN / ACK TIME_WAIT 2 × MSL connect() close() the useful work no state full state both ends active closer lingers
Connection states · select one

Putting it together

The sequence diagram below traces one complete session from the first SYN to the final ACK, with sequence numbers shown for a connection whose client ISN is 1001 and server ISN is 5001. Trace how every ACK equals the peer’s last sequence number plus the bytes it carried.

   Client (10.0.0.10:52413)                         Server (203.0.113.5:80)
         |                                                       |
         |  SEQ=1001  ACK=0        [SYN]                         |
         |------------------------------------------------------>|   1 open
         |  SEQ=5001  ACK=1002     [SYN, ACK]                    |
         |<------------------------------------------------------|   2
         |  SEQ=1002  ACK=5002     [ACK]                         |
         |------------------------------------------------------>|   3 established
         |                                                       |
         |  SEQ=1002  ACK=5002  len=100   (bytes 1..100)         |
         |------------------------------------------------------>|
         |  SEQ=5002  ACK=1102     [ACK]                         |   receiver wants byte 101
         |<------------------------------------------------------|
         |                                                       |   ... session continues ...
         |  SEQ=1102  ACK=5002  len=100   (bytes 101..200)       |
         |------------------------------------------------------>|
         |                          ... segment lost in transit ...
         |  SEQ=1102  ACK=5002  len=100   (retransmission)       |   timer fires, resend
         |------------------------------------------------------>|
         |  SEQ=5002  ACK=1302     [ACK]                         |
         |<------------------------------------------------------|
         |                                                       |
         |  SEQ=1302  ACK=5002     [FIN]                         |   client done sending
         |------------------------------------------------------>|
         |  SEQ=5002  ACK=1303     [ACK]                         |   phase 2
         |<------------------------------------------------------|
         |  SEQ=5002  ACK=1303     [FIN]                         |   server done sending
         |<------------------------------------------------------|
         |  SEQ=1303  ACK=5003     [ACK]                         |   phase 4
         |------------------------------------------------------>|
         |      (client enters TIME_WAIT, then CLOSED)           |

This one picture contains almost everything the exam asks about TCP connection management: the handshake, cumulative acknowledgment, a timer-driven retransmission, and a four-message teardown with FIN consuming a sequence number.

Key terms

TermMeaning
Sequence numberThe position in the sender’s byte stream of the first data byte in a segment.
Acknowledgment numberThe next byte the receiver expects; acknowledges all earlier bytes cumulatively.
ISNInitial sequence number; a random starting point chosen at connection setup.
RTORetransmission timeout; the adapted time a sender waits before resending unacknowledged data.
Duplicate ACKA repeated acknowledgment naming data the receiver still lacks; three of them trigger fast retransmit.
FINFinish flag; closes one direction of a connection. Consumes one sequence number.
RSTReset flag; aborts a connection immediately with no negotiation.
TIME_WAITThe state the active closer holds for about 2×MSL to catch a retransmitted FIN and let old segments expire.
Half-open connectionOne endpoint has state for the session while the other does not.
Half-closed connectionA normal teardown state: one direction has sent FIN, the other is still sending.
Part 7 · Your turn

Review

Check what you have learned with these review questions.

Review · 6 questions

Sources

Sources & references

  1. Postel, J. RFC 793: Transmission Control Protocol (1981), Sections 2.6 (sequence numbers), 3.3–3.5 (retransmission, data communication), and 3.5 (Closing a Connection, TIME-WAIT). rfc-editor.org/rfc/rfc793.
  2. Braden, R. RFC 1122: Requirements for Internet Hosts — Communication Layers (1989), Sections 4.2.2 (retransmission), 4.2.2.1 (establishment), and 4.2.2.2 (closing). rfc-editor.org/rfc/rfc1122.
  3. Paxson, V., Allman, M., Chu, J. & Sargent, M. RFC 6298: Computing TCP's Retransmission Timer (2011). rfc-editor.org/rfc/rfc6298.
  4. Cisco. CCNA (200-301) Exam Topics, IP Services / TCP/IP transport. cisco.com.

Target exams: CCNA 200-301 v1.1 · CyberOps Associate 200-201. Last content verification: 2026-10-11.