← Back to list

The Invisible TCP Handshake Behind Every Website You Open

Every time you open a website, a webpage appears perfectly on your screen within seconds.

Ombendre · 2026-05-27 11:00 · 16 claps · 5.0 min read
#tcp #tcp-three-way-handshake #computer-networking #cybersecurity
Open on Medium ↗
Wiki topics: 🔒 · Cybersecurity

The Invisible TCP Handshake Behind Every Website You Open

Every time you open a website, a webpage appears perfectly on your screen within seconds.

But have you ever wondered how such a huge data travel across the internet and still arrive in the correct order instead of appearing completely messed up?

Before any webpage is displayed, your computer and the server first establish a reliable connection.

But even before that, the browser first needs to know the server’s IP address using DNS. (If you want to understand that process first, you can read the previous DNS blog here: https://medium.com/@ombendreblogs/dns-explained-how-the-internet-finds-websites-in-milliseconds-3ff298fc410a )

Now this brings us to the next obvious question:

“Why Does a Connection Need to Be Established?”

See internet may feel very smooth and reliable but, in reality its congested and imperfect.

So, the data traveling across networks can face many problems like:

  • Data packets may get lost
  • Late arrival of packets
  • Packets may arrive in the wrong order
  • Some may never reach the destination at all

If browsers started communicating with server without a reliable connection then:

It would be like sending the pages of a book in different envelopes. and so:

  • Some envelopes didn’t reach,
  • some arrive late,
  • some arrive, but not in order.

And at last you end up with a meaningless book.

So before actual communication begins, both systems first synchronize with each other and should agree on how communication will happen.

That reliable connection-building process is handled by TCP.

What Exactly Is TCP?

TCP stands for:

Transmission Control Protocol

In simple words, TCP makes sure that data:

  • reaches properly
  • arrives in the correct order
  • and missing data can be detected.

But one of the most important things about TCP is that it is:

Connection-Oriented

Now you might wonder:

“What does connection-oriented actually mean?”

It means TCP does not start sending data immediately.

Before any real communication happens, the client and server first establish a reliable connection and make sure both sides are ready to communicate properly.

And that connection is build by a very interesting process called:

TCP Three-Way Handshake

TCP Three-Way Handshake

You can think of it like a phone call.

The caller says: “Hello, I want to talk.”

The receiver replies: “Hello, I can hear you, and I’m ready to talk as well”

Then the caller confirms: “okay now let’s start the conversation.”

Only after this confirmation the real conversation begin.

TCP works in a very similar way.

TCP packets contain special header information that helps the receiver understand:

  • who sent the data
  • where it should go
  • whether they are in order
  • whether packets arrived correctly

The headers are:

  • source port (port number of sender)
  • destination port (port number of receiver)
  • sequence number
  • acknowledgement number
  • flags (like SYN,ACK,FIN)
  • checksum (used to detect data corruption during transmission)
  • data (the actual request or response being transferred)

“But wait a minute… what are ports?”

You know that IP address identifies a machine on the network.

But one machine can run many different services simultaneously.

For example:

  • a web service
  • a database service
  • a mail service
  • and many other services.

So how does the operating system of that machine (client or server) know which service should receive incoming data?

That is where ports come in.

You can think of it like this:

The IP address tells you which colony but the actual house is mapped by the ports.

TCP connections are established between:

IP Address + Port

on both the client and server sides.

Okay, so now that you understood how ports helps to identify correct service

So here comes the TCP’s crazy logic of reliable connection

For that TCP uses:

· Sequence number (SEQ NUM) — It is a randomly generated starting number used by TCP to track the sequence of data. SEQ NUM is sent by sender every time when it communicates.

Like each page in book has a page number to map that specific page similarly each SEQ NUM maps a specific data during the communication.

· Acknowledgement number (ACK NUM) — When the data packet sent by sender is received by receiver then the receiver sends a number which is +1 to the last sequence number that sender had sent.

For ex. if receiver gets data packet with SEQ NUM 1104 so now receiver will send 1105 as acknowledge number which means receiver now expects the data packet with SEQ NUM 1105 and have received all the data packets upto 1104.

· flags :

Flags tells the purpose of the packet.

If SYN = 1 then the purpose is to start a TCP connection and synchronize sequence numbers.

If ACK = 1 then the purpose is to confirm that the data is received.

Now lets move towards the actual process of TCP three way handshake

Step 1 — Client Sends SYN

The client sends:

SYN = 1 SEQ NUM = 1000

Meaning:

“I want to establish communication and my starting sequence number is 1000.”

Step 2 — Server Sends SYN-ACK

Now server will also communicate from its side right?

So server also randomly generates:

SEQ NUM = 5000

Then server replies with:

SYN = 1 ACK = 1 SEQ NUM = 5000 ACK NUM = 1001

The server is basically saying:

“I successfully received your sequence number 1000, and now I expect 1001 next.”

Also, the server shares its own starting sequence number:

5000

Step 3 — Client Sends Final ACK

Now the client acknowledges the server’s sequence number too.

Client sends:

ACK = 1 SEQ NUM = 1001 ACK NUM = 5001

Meaning:

This means the client successfully received the server’s sequence number 5000 and now expects 5001 next.

And with this final synchronization:

  • both sides know what sequence numbers to expect
  • both sides get confirmation that communication works properly
  • and the TCP connection becomes fully established.

Why Sequence Numbers And ACK Numbers Are Needed?

Suppose the receiver successfully receives packets with sequence numbers:

1001, 1002, 1003

Now the receiver expects:

1004

But instead, packet:

1005 arrives first.

Now what….?

Now the receiver understands that something is missing because the incoming sequence number does not match the expected one.

So instead of moving forward, the receiver keeps expecting 1004 packet by acknowledging only up to:

1003

which tells the sender:

“I am still waiting for packet 1004.”

But what about that 1005 packet? :

It will be stored in buffer and when the 1004 arrive successfully the 1005 is also accepted and buffer is cleared.

And this is the reason why TCP is considered as reliable way of communication.

Final Thoughts

If you’ve reached here, then you finally have the answer to a question most people never even think about that:

“How do webpages, emails, and messages arrive perfectly in order without getting completely messed up during transmission?”

What feels like a simple click in a browser/application is actually triggering a very coordinated process of making reliable connection between client and server behind the scenes.

In the next blog, we’ll continue this journey and explore what happens after the TCP connection is established that is:

  • how HTTP requests are sent
  • how servers respond
  • and how actual webpage data travels across the internet.

About Me

I’m currently exploring networking, cybersecurity, and system internals, and I’ll be sharing more blogs from my learning journey.

Feel free to connect with me:

linked in : www.linkedin.com/in/om-bendre22


메타데이터
post_id
98ea0e3d93b9
slug
the-invisible-tcp-handshake-behind-every-website-you-open-98ea0e3d93b9
url
https://medium.com/@ombendreblogs/the-invisible-tcp-handshake-behind-every-website-you-open-98ea0e3d93b9
canonical_url
https://medium.com/@ombendreblogs/the-invisible-tcp-handshake-behind-every-website-you-open-98ea0e3d93b9
author_url
https://medium.com/@ombendreblogs
status
ok
fetched_at
2026-06-09 15:37:30