When it is time to close the connection, the computer initiating the close, Computer A, places a segment in the queue with the FIN flag set to one.
The application then enters what is called the fin-wait state. In the fin-wait state, Computer A's TCP software continues to receive segments and processes the segments already in the queue, but no additional data is accepted from the application.
When Computer B receives the FIN segment, it returns an acknowledgment to the FIN, sends any remaining segments, and notifies the local application that a FIN was received.
Computer B sends a FIN segment to Computer A, which Computer A acknowledges, and the connection is closed