TCP, UDP and the Handshake — Web Fundamentals

TCP is a protocol (a set of rules for talking) that opens a connection with a handshake of three messages: SYN, SYN-ACK, ACK. Then TCP puts the packets back…

In the basics you saw the five steps of opening a page, and a page cut into small packets. This lesson looks more closely at the second step (knocking on the door): how the browser and the server agree on a connection, and what keeps the packets complete.

The five steps, with their protocols

Here are the five steps with their technical names:

1. DNS       "what is the IP of belajarweb.dev?"  →  203.0.113.10
2. TCP       SYN → SYN-ACK → ACK   (handshake)
3. Request   GET / HTTP/1.1
4. Response  HTTP/1.1 200 OK + the page (HTML)
5. Render    the browser draws the page on screen

HTTP/1.1 in lines 3 and 4 is the HTTP version.

DNS, TCP and HTTP (the language of requests and replies) are each called a protocol: a set of rules both sides agree on for talking. When the address starts with https://, there is one more handshake after the TCP handshake, for encryption (sealing what is inside the messages), called TLS.

TCP makes sure every packet arrives

TCP (Transmission Control Protocol) is the protocol that makes sure data arrives complete and in order. It does this in two ways:

UDP (User Datagram Protocol) works the opposite way: it just sends, with no handshake and no resending. UDP is faster, but a lost packet stays lost. UDP suits video calls and online games, where resending would come too late to help.

⚠️ What people get wrong about the internet

💡 HTTP/3 takes another road. Many sites now use HTTP/3, a version of HTTP that travels over QUIC, not TCP. QUIC is a newer protocol that uses UDP, but it still guarantees complete, in-order data like TCP does. QUIC also combines the connection handshake with the encryption handshake, to save time.

TL;DR: TCP is a protocol (a set of rules for talking) that opens a connection with a handshake of three messages: SYN, SYN-ACK, ACK. Then TCP puts the packets back in order by their numbers and resends the lost ones. UDP, another protocol, sends right away with no handshake and no resending: faster, with no guarantee. HTTP/3 (a newer version of HTTP) travels over QUIC, which uses UDP but still guarantees complete, in-order data.

⚡ The five steps have protocol names

Meaning: When you open a page, DNS finds the IP address, TCP opens a connection with a handshake, and HTTP is the language of requests and replies. Each one is called a protocol: a set of rules both sides agree on for talking. When the address starts with https://, there is one more handshake after the TCP handshake, for encryption (sealing what is inside the messages), called TLS.

⚡ The three-way handshake

Guess first: how many messages pass before TCP sends its first data?

Three: the client sends SYN ("can we open a connection?"), the server answers SYN-ACK ("yes, are you ready?"), and the client sends ACK ("ready").

Meaning: This is the three-way handshake. ACK means a receipt. After the handshake, the connection is open. TCP then puts the packets back in order by their numbers and resends the ones that didn't arrive.

⚡ UDP just sends

Guess first: UDP is a protocol that sends data right away, with no handshake. On a video call over UDP, a packet gets lost. Is that packet sent again?

No. UDP never resends a lost packet. On a video call, resending would come too late to help.

Meaning: UDP is faster, but a lost packet stays lost. HTTP/3 (a newer version of HTTP) travels over QUIC, which uses UDP but still guarantees complete, in-order data.

⚡ Latency is not bandwidth

Meaning: Latency is how long one message takes to travel, in milliseconds (ms). Bandwidth is how much data per second, in Mbps (megabits per second). A 100 Mbps connection with 300 ms of latency still feels slow in a game, because every message still spends 300 ms on the road.

What you will learn