Step through the three-way handshake that opens a TCP connection, a short data exchange, and the four-way teardown that closes it. Sequence numbers below are simplified for clarity.
Two segments wouldn't be enough. TCP needs both sides to prove they can send and receive, and both sides need to pick and confirm a random initial sequence number so both ends can track exactly which bytes have been sent and received.
| Flag | Meaning |
|---|---|
| SYN | "Synchronize" — requests a new connection and proposes an initial sequence number. |
| ACK | Acknowledges data or a control flag was received; carries the "ack" number, which is always one more than the last byte received. |
| PSH | "Push" — tells the receiving OS to hand the data straight to the application instead of buffering it, used for interactive data. |
| FIN | "Finish" — sender has no more data to send and wants to close its side of the connection. |
| RST | "Reset" — abruptly aborts a connection, e.g. when a segment arrives for a port nothing is listening on. Not part of a normal handshake or teardown. |
| URG | "Urgent" — marks part of the segment as needing out-of-band priority handling. Rarely used in modern applications. |