What is the 3-way handshake in TCP?
Answer
The TCP 3-way handshake is the process by which a TCP connection is established between a client and server before any data is exchanged. Step 1: SYN — the client sends a segment with the SYN (synchronize) flag set and a random Initial Sequence Number (ISN). Step 2: SYN-ACK — the server responds with both SYN and ACK flags set, its own ISN, and an acknowledgment of the client's ISN + 1. Step 3: ACK — the client sends an ACK acknowledging the server's ISN + 1. After this, the connection is established and bidirectional data transfer can begin. TCP connection termination uses a 4-way handshake (FIN → FIN-ACK → FIN → FIN-ACK). The handshake establishes sequence numbers for ordered delivery and confirms both sides can send and receive — this is why TCP is reliable but has higher setup latency than UDP.