Lesson 3 of 4 · 7 min
The TCP handshake and a connection’s life
How two computers agree to talk before either sends real data, how they end the conversation, and what a firewall watching in the middle actually sees.
Before your Mac sends a single byte of a webpage request, it has already exchanged three short messages with the server. That exchange, the TCP three-way handshake, is what turns TCP’s reliability promises from the previous lesson into an actual, trackable connection between two machines.
Three messages before the first word
RFC 9293, the current TCP specification, describes the process as a synchronized exchange: “the synchronization requires each side to send its own initial sequence number and to receive a confirmation of it in acknowledgment from the remote TCP peer.”
- SYN. The device opening the connection sends a segment with the SYN flag set, carrying a starting sequence number.
- SYN-ACK. The other side replies with its own SYN, plus an acknowledgment of the first number.
- ACK. The first device acknowledges that reply. RFC 9293 notes that “because steps 2 and 3 can be combined in a single message this is called the three-way (or three message) handshake.” Once it completes, both sides count the connection as ESTABLISHED and start sending real data.
Cloudflare’s Learning Center gives a plain-language version of the same idea, using an email as the example: “first, the source sends an SYN ‘initial request’ packet to the target server in order to start the dialogue. Then the target server sends a SYN-ACK packet to agree to the process. Lastly, the source sends an ACK packet to the target to confirm the process, after which the message contents can be sent.”
Ending a connection cleanly
Closing is more deliberate than opening. RFC 9293 explains that “the normal TCP close sequence delivers buffered data reliably in both directions” before the connection ends: each side sends a FIN segment once it has no more data to send, the other side acknowledges it, and only once both directions have finished does the connection fully close. A short waiting period (TIME-WAIT) follows, so that any stray, delayed packet from the old connection cannot be mistaken for part of a new one.
What a firewall in the middle sees
A stateful firewall, the kind built into most routers and into macOS itself, does not need to inspect every packet to make a decision. Cloudflare’s explanation of firewalls describes it this way: it “saves information regarding open connections and uses this information to analyze incoming and outgoing traffic, rather than inspecting each packet.” In practice, that means it watches for the SYN that opens a connection, remembers that this app asked for a reply, and then quietly allows the matching SYN-ACK back in; a reply that does not match any outgoing SYN gets dropped. That is also how a firewall can tell a normal reply from an unsolicited connection attempt arriving out of nowhere, which is the basis of blocking unwanted inbound traffic.
None of this exchange is encrypted by TCP itself; SYN, SYN-ACK and ACK are visible in plain form to anything watching the network path, including your Wi-Fi router. What is hidden or not depends on the layer above TCP, such as TLS for an HTTPS site, which the how-the-internet-works course covers separately.
Key takeaways
- TCP connections open with a three-way handshake: SYN, then SYN-ACK, then ACK, per RFC 9293.
- Only after the handshake completes do the two sides start exchanging real data.
- Closing a connection is a two-way exchange of FIN segments so buffered data is delivered before the connection ends.
- A stateful firewall tracks which SYNs went out so it can recognize and allow the matching replies, and drop unsolicited ones.
- The handshake itself is not encrypted; it is visible to anything on the network path.
Check yourself
1. What is the correct order of the TCP three-way handshake?
- ACK, SYN, SYN-ACK
- SYN, SYN-ACK, ACK — Right.
- SYN-ACK, SYN, ACK
- FIN, SYN, ACK
RFC 9293 describes the connecting side sending SYN first, the other side replying with SYN-ACK, and the connecting side confirming with ACK.
2. When does real application data start flowing over a TCP connection?
- Before the SYN is sent
- Only after the three-way handshake completes — Right.
- During the SYN-ACK step
- Data flows continuously with no handshake
The handshake exists to synchronize sequence numbers before either side trusts the connection enough to send real data.
3. How does a stateful firewall decide to allow an incoming reply packet?
- It allows all incoming packets by default
- It checks whether the packet matches a connection this device opened, remembered from the earlier outgoing SYN — Right.
- It inspects the packet’s contents for keywords
- It only looks at the destination port, never the connection state
Cloudflare describes a stateful firewall as one that "saves information regarding open connections" to recognize legitimate replies rather than inspecting every packet from scratch.
4. Is the TCP handshake itself encrypted?
- Yes, always
- No, it is plain and visible to anything on the network path — Right.
- Only the SYN is encrypted
- Only on HTTPS connections
TCP provides ordering and reliability, not confidentiality. Encryption, when present, comes from a layer above TCP such as TLS.
Do it with FireAI
Put this lesson into practice on your own Mac.
- Find out where an app sends data, on the World map — See exactly which company and country one app is quietly talking to.
- Rules: app, website, domain, IP or a range, forever or until you restart — Write a rule as precise as one address or as broad as an entire domain.
- Deep inspection, without decrypting anything — Get real detail on a secure connection without FireAI ever reading what’s inside it.
Sources
- RFC 9293: Transmission Control Protocol (TCP)
- Cloudflare Learning: What is TCP/IP?
- Cloudflare Learning: What is a Firewall?
Put it into practice on your Mac
Try every feature free for 17 days, no card needed.