Course contentsShow
← Computer Science
Lesson 1474 of 2,87234. Internet Protocol SuiteFree lesson

TCP Connection Termination

The four-way handshake process (FIN, ACK, FIN, ACK) for gracefully closing TCP connections.

TCP Connection Termination

You'll learn: How TCP uses a four-way handshake to cleanly shut down connections so both sides agree the conversation is truly over.

Why Not Just Hang Up?

When two computers finish communicating over TCP, they can't just drop the connection abruptly—they might lose data or leave resources dangling. TCP uses a graceful shutdown process called the four-way handshake to ensure both sides are ready to close.

The Four-Way Handshake

Think of it like ending a phone call politely:

Step 1: FIN from Initiator

One side (let's call it Host A) decides to close. It sends a FIN (finish) segment, saying "I'm done sending data."

Step 2: ACK from Receiver

The other side (Host B) replies with an ACK (acknowledgment), confirming "I heard you want to close."

At this point, Host A won't send more data, but Host B might still have data to send—the connection is "half-closed."

Step 3: FIN from Receiver

When Host B finishes its own data transmission, it sends its own FIN: "Now I'm done too."

Step 4: Final ACK

Host A sends a final ACK back to Host B, confirming receipt. The connection is now fully closed.

Why Four Steps Instead of Two?

TCP is full-duplex—data flows both directions independently. Each direction must be closed separately. Host B might need time after receiving the first FIN to finish sending its own data before it's ready to close its side.

Key Takeaway: TCP connection termination uses a four-way handshake (FIN, ACK, FIN, ACK) to gracefully close both directions of communication, ensuring no data is lost and both sides agree the connection is finished.