TCP/IP Explained
Demystifying SYN, SYN-ACK, and ACK
How RFC 793 forces order and guaranteed delivery over the chaotic, stateless internet.

At its lowest level, the physical infrastructure of the internet offers absolutely no guarantees. When a router transmits a packet of data across a fiber optic cable, it simply fires the packet into the void. Cables get cut, routers drop packets when overloaded, and data often arrives out of order. This base layer is known as the Internet Protocol (IP), and it is entirely stateless.

If an application needs to send a 5GB database backup, it cannot rely on IP alone. If chunk #482 is dropped in transit, the entire file is corrupted, and the receiving server has no way of knowing it missed a piece.

To solve this, engineers rely on the Transmission Control Protocol (TCP), formally defined in RFC 793. TCP operates directly on top of IP, creating a temporary, stateful connection that guarantees perfect data delivery. Before a single byte of application data is sent, TCP forces the two machines to negotiate the rules of engagement. This negotiation is the 3-Way Handshake.

The Foundation: Sequence Numbers
The magic of TCP relies entirely on tracking sequence numbers.
When a computer sends data over TCP, it does not just send raw bytes. It assigns a specific numerical sequence to every single byte. If the receiver gets bytes 1 through 100, and then receives bytes 201 through 300, it mathematically knows that bytes 101 through 200 were lost in transit. The receiver will halt the process and demand the sender retransmit the missing data.

However, a connection cannot just start at sequence number 1. This would make the connection highly vulnerable to network attacks (like TCP spoofing) and confusion from delayed packets belonging to old, closed connections.
Note: TCP spoofing is an attack where an unauthorized user impersonates a trusted IP address to establish a Transmission Control Protocol (TCP) connection. By forging the source IP, attackers can bypass critical security checks such as firewalls, IP-based authentication, and email allowlists like SPF records.
Instead, both the client and the server must independently generate a completely random Initial Sequence Number (ISN). The entire purpose of the 3-Way Handshake is for the two machines to exchange and acknowledge these random starting numbers before the real data starts flowing.
Step 1: SYN (Synchronize)

The process begins when a client (like your web browser) wants to talk to a server.
The client generates its random ISN—for example, 5000. It creates an empty TCP packet, sets a specific binary flag in the packet header called SYN (Synchronize), and sends it to the server.
This packet translates to: “I want to establish a secure connection with you, and my data stream is going to start at sequence number 5000.”



