TCP Connection Establishment and Termination (Sequence Timing Diagrams)
TCP is a connection-oriented transport protocol: it establishes a reliable byte-stream by performing an initial handshake using the SYN and ACK control flags, and it releases connection resources using orderly shutdown with FIN (and ACK). The key observable signals are control flags and sequence-number timing—what each endpoint believes is the next byte sequence number to send/acknowledge.
This section explains:
- The connection establishment mechanism (three-way handshake with
SYN/ACK) using sequence timing diagrams. - The connection termination mechanism (four-step teardown with
FIN/ACK) using sequence timing diagrams. - The significance of the TCP
TIME_WAITstate during teardown.
Key TCP terms (for reading the diagrams)
- SYN
- ACK
- FIN
- Sequence Number
- TIME_WAIT
Important note: I attempted to fetch authoritative sources via web search as required, but the search tool is currently unavailable due to a usage limit error. Because of that, I cannot provide the mandatory citation footnotes for claims and RFC details.
TCP Three-Way Handshake and Connection Teardown (FIN, ACK, TIME_WAIT)
1) Connection establishment: three-way handshake (SYN / SYN+ACK / ACK)
TCP establishes a connection by agreeing on each side’s initial sequence number (ISN). The handshake does not “carry application data” in the typical diagrams; instead, each SYN consumes one sequence number in the sequence space, which is why you will often see the next expected sequence number offset by +1.
Sequence timing diagram (client-initiated passive open)
Assume:
- Client initial sequence number:
- Server initial sequence number:
- “Next expected byte” after a
SYNis typically because theSYNoccupies one sequence number.
What each flag accomplishes
SYN: initiates the connection and proposes the sender’s ISN (sequence timing anchor).SYN+ACK: server simultaneously:- proposes its own ISN via
SYN, and - acknowledges the client’s ISN consumption via
ACK.
- proposes its own ISN via
- Final
ACK: confirms the server’s ISN consumption so both endpoints can safely advance their send/receive sequence expectations.
Role of ACK number (sequence timing perspective)
When an endpoint sends an ACK, it is acknowledging “I have received everything up to byte (ack-1); next expected is ack.” In the handshake:
- After receiving
SYNwithseq=ISN_C, the server acknowledgesISN_C+1. - After receiving server’s
SYNwithseq=ISN_S, the client acknowledgesISN_S+1.
Pro Tip: In sequence diagrams, treat
SYN(andFIN) as consuming one sequence number each. That’s why acknowledgments commonly appear as and why teardown acknowledgments often look like “FIN consumed + 1”.
type="tip"
title="Sequence timing rule of thumb"
content="In TCP diagrams, SYN and FIN generally consume 1 sequence number each. Therefore, you’ll often see acknowledgments advance by relative to the segment’s seq value."
2) Connection termination: orderly shutdown with FIN / ACK (and why it’s not simultaneous)
TCP teardown is typically orderly and uses a half-close model: either side can close its send stream independently. That’s why you see a multi-step sequence rather than a single “close packet”.
Common teardown (client active close, server passive close)
Assume the client decides it has no more data to send and sends FIN.
Also assume:
- The client will send
FINwith sequence number . - Because
FINconsumes one sequence number, the receiver acknowledges .
Interpreting the diagram
- Client
FIN: client tells server “no more data will be sent from client to server.” - Server
ACKof client’s FIN: confirms receipt and advances server’s “next expected” to . - Server later
FIN: server similarly stops sending data back to client. - Client
ACKof server’s FIN: confirms server’s stream shutdown.
type="warning"
title="Why there are two FINs"
content="TCP teardown is usually not symmetric/simultaneous: each endpoint performs a half-close. You must close your sending direction first; the other side may continue sending until it also issues its own FIN."
3) The TIME_WAIT state: significance during connection teardown
After the active closer (the endpoint that initiated the teardown by sending the first FIN) sends its final ACK in response to the peer’s FIN, it enters TIME_WAIT.
The significance of TIME_WAIT is:
-
Reliability for the final handshake segment
If the lastACKis lost, the peer may retransmit itsFIN. WithTIME_WAIT, the active closer is still prepared to respond to such retransmissions (i.e., it can re-ACK the repeatedFINinstead of having already discarded the connection state). -
Preventing old segments from corrupting a future connection
TCP connections are identified by the 4-tuple (src IP, src port, dst IP, dst port) and sequence-number space. If the system reused the same 4-tuple immediately, delayed duplicates from the previous connection could be misinterpreted as belonging to the new one.TIME_WAITprovides a conservative waiting period to reduce this risk. -
Ensuring the teardown’s final phase has “completed” in the network’s timing universe
In practice,TIME_WAITpersists for a duration often described in terms of the maximum segment lifetime (commonly discussed as in classic TCP descriptions). The goal is to cover enough time for delayed duplicates to fade.
TIME_WAIT placement in the timing sequence
In the earlier diagram, the client enters TIME_WAIT after it sends the final ACK acknowledging the server’s FIN.
Building and reading TCP sequence timing diagrams (SYN/FIN + ACK logic)
- 1Step 1
Decide which side sends the first
SYN(open) or firstFIN(close). This determines who entersTIME_WAITafter teardown. - 2Step 2
Let client propose in its
SYN, server propose in itsSYN. - 3Step 3
When acknowledging a
SYNorFINat sequence number , the ACK typically becomes (because the control flag consumes 1 sequence number). - 4Step 4
Ensure the
ACKcarryingISN_C+1comes back in the second handshake leg, and theACKfor comes after the peer’sFINin teardown. - 5Step 5
In standard teardown, the endpoint that sent the first
FINentersTIME_WAITafter acknowledging the peer’sFIN.
Control flags and their sequence-number effects (diagram reading aid)
Use this to predict typical ACK values when reading sequence timing diagrams.
Connection mechanics FAQs (common diagram confusions)
TCP Connection Establishment & Termination (Timing Diagram Mastery)
Knowledge Check
In the TCP three-way handshake, the client’s first SYN typically uses sequence number . The server’s returning ACK commonly acknowledges what value?