- Published on
The Full Path of One Web Request to the Server (+ VPN, SSH)
- Authors

- Name
- seren-wib
Contents
- The whole picture
- 0. Setup: join the network and get an address
- Wi-Fi connection
- Router ↔ ISP
- DHCP
- 1. URL parsing
- 2. DNS: name → IP
- 3. Same network or not + ARP
- Subnet check
- ARP
- 4. TCP connection (3-way handshake)
- 5. TLS setup (because it is HTTPS)
- 6. HTTP request + encapsulation (sender side, top → bottom)
- 7. Link 1: laptop → router (Wi-Fi)
- 8. Router: firewall + routing + NAT
- 9. Link 2 onward: ISP → internet → server side (repeated at every router hop)
- 10. Server side: arrival + decapsulation + processing
- 11. Response: the same road in reverse
- 12. Browser: turning it into a page
- 13. Closing the connection
- What changes on each link vs what stays
- 14. When using a VPN
- Connection setup
- When sending
- Who sees what
- Caveats
- 15. Connecting over SSH
- When you type ssh user@server.example.com
- Reaching a PC behind NAT
- SSH tunnel
This post follows one packet from a laptop on home Wi-Fi opening
https://www.example.com/videoall the way to the web server and back, in steps 0 to 13. At the end it adds what changes when a VPN is on and when you connect over SSH. It started as a note I wrote while studying lecture 5 (networking) of Introduction to Computer Systems (컴퓨터시스템개론), covering more than the slides did. The same material grouped by layer (application, transport, network, link, physical) is in Networking by Layer. The same material grouped by layer (application, transport, network, link, physical) is in Networking by Layer.
The whole picture
Think of a parcel. The sender puts the item in a box, puts that box in a bigger box, and sticks a shipping label on the outside. At every sorting center the outer label is replaced with one for "the next center", but the final address written on the inner box stays the same all the way.
Laptop → home router → ISP router → router B → web server. The box below is the frame on the current link, and red text marks values that change when the link changes. Diagram labels are in Korean.
In the analogy, the nested boxes are encapsulation, the outer label is the link layer header (MAC addresses), the final address on the inner box is the destination IP in the IP header, and the sorting centers are routers.
How to read the diagram
- Top: laptop → home router → ISP router → router B → web server. Links 1 to 4 are the hops between devices.
- Bottom box: the frame flying over the current link. From the outside in: link header (MAC) ⊃ IP header ⊃ TCP header ⊃ HTTP encrypted with TLS.
- Red text: values that change when the link changes. The destination IP and destination port stay the same to the end.
The whole flow in one line: the sender goes down four layers doing encapsulation → each router looks only at the IP header and passes the packet to the next link → the receiver goes up four layers doing decapsulation.
Example addresses (all reserved for documentation)
| Device | Address |
|---|---|
| Laptop (private) | 192.168.1.20 |
| Router (LAN side) | 192.168.1.1 (default gateway) |
| Router (public) | 203.0.113.5 |
| Web server | 192.0.2.10 |
0. Setup: join the network and get an address
Think of your first day in a new apartment. You need a building pass (the wireless connection), and the management office has to give you your unit number and where the nearest post office is (IP and gateway) before you can send any mail. The building pass is Wi-Fi association, and the management office is the DHCP server.
Wi-Fi connection
- Scan: find the SSID in the beacons the AP broadcasts.
- Authentication and association.
- The WPA2/3 4-way handshake creates the encryption keys for the wireless link.
At this point only the laptop ↔ AP connection exists. Whether you can reach the internet is still unknown. The ISP and server links are separate.
Router ↔ ISP
The router's WAN port connects to the ISP network through a modem or ONT (optical network terminal). The public IP 203.0.113.5 is the address the ISP gave the router.
DHCP
The router hands out IPs automatically. It takes four steps, called DORA after their first letters.
- Discover: broadcast "anyone giving out IPs?" There is no IP yet, so it goes 0.0.0.0 → 255.255.255.255, UDP 68 → 67.
- Offer: the router offers 192.168.1.20.
- Request: "I'll take that."
- Ack: confirmed.
What you get: your IP, the subnet mask (/24), the default gateway (= the router, 192.168.1.1), DNS server addresses, and the lease time.
The default gateway is the exit to other networks. It is usually the IP of a router interface on the same LAN.
1. URL parsing
The browser splits the URL.
- Scheme
https→ default port 443 - Host
www.example.com - Path
/video
If the browser cache still has a valid response, nothing goes out on the network and it ends here (web cache).
2. DNS: name → IP
It works like a phone book. People know the name (www.example.com), but calling needs the number (IP). You ask the local operator (the resolver), and the operator asks head office → regional branch → the responsible department in turn and tells you the number. The local operator is the recursive DNS resolver, and head office, branch and department are the root, TLD and authoritative DNS servers.
Check the caches first: browser DNS cache → OS DNS cache → the hosts file. If one has it, it ends here.
If not, the device asks the recursive DNS resolver (the DNS server from DHCP, usually the ISP's or the router). The query is usually UDP 53. This DNS query packet also goes out and back through ARP → gateway → NAT → router hops, exactly like steps 3 and 6 to 9 below.
The resolver asks on your behalf, in order. Each server only says "ask over there next."
- Root DNS server: where the
.comserver (TLD server) is - Top-level domain (TLD) DNS server: where the server for
example.com(authoritative server) is - Authoritative DNS server: the official record for
www.example.com→ A record 192.0.2.10
The resolver caches the result for the record's TTL. The next person who asks for the same name gets it right away. For large services, the authoritative server may return the IP of a nearby CDN server. Buying a domain and setting DNS records yourself is covered in DNS and Registrar.
3. Same network or not + ARP
Mail for a neighbor in the same building you can leave at their door. Mail for another town has to go through the post office. To hand it to the post office you need to know where its counter is (MAC), and asking that over the building's PA system is ARP.
Subnet check
AND your IP and the server IP each with the subnet mask and compare the network addresses. 192.168.1.0 ≠ 192.0.2.0 → different networks. How to compute it is in How to find which subnet an arbitrary IP belongs to.
- Same: send directly inside the LAN to the peer's MAC.
- Different: send to the default gateway.
ARP
You know the gateway IP (192.168.1.1) but not its MAC.
- Check the ARP cache first.
- If it is not there, broadcast an ARP request: "who is 192.168.1.1?" (destination MAC
FF:FF:FF:FF:FF:FF) - The router sends an ARP reply with its MAC (unicast).
- Save it in the ARP cache. No need to ask next time.
So the first frame has destination MAC = router and destination IP = server. The two point at different things. Why two addresses are needed is in IP and MAC complement each other.
4. TCP connection (3-way handshake)
On a phone call you say "Hello?" → "Yes, I can hear you. Can you hear me?" → "Yes" before getting to the point. Those three lines are SYN → SYN+ACK → ACK.
- The browser creates a socket. The OS picks a temporary source port (ephemeral port, e.g. 51000), and the destination port is 443.
- SYN (seq = x, options such as MSS) → SYN+ACK (seq = y, ack = x+1) → ACK (ack = y+1)
- This does not connect a wire. It creates connection state on both sides (starting sequence numbers and so on).
- Each of the three segments makes the round trip through steps 6 to 9. This costs 1 RTT.
A field-by-field explanation is in Three-Way Handshake process.
5. TLS setup (because it is HTTPS)
This step builds a cipher only the two sides know. First you check the business registration (certificate) to make sure the shop is real, then the two sides exchange numbers and each builds the same key on its own. The key itself never travels. The business registration is the server certificate, and the key each side builds is the session key.
For TLS 1.3:
- ClientHello: supported cipher suites, key exchange value, the name to connect to (SNI =
www.example.com) - ServerHello: the chosen suite, the server's key exchange value + certificate + signature + Finished
- The browser verifies the certificate: CA signature chain, certificate domain = the domain you connected to, validity period.
- Finished → both sides compute the same session key (ECDHE key exchange, the key itself is never sent).
After that, HTTP data is encrypted with the session key (symmetric key).
What it protects: confidentiality (can't read it), integrity (you notice if it changes), and server authentication. It does not guarantee that the site's content is genuine. Phishing sites use HTTPS too.
6. HTTP request + encapsulation (sender side, top → bottom)
The parcel analogy from the start actually happens here. Each layer adds one more box and one more label.
HTTP request: GET /video HTTP/1.1, Host: www.example.com, cookies, browser info and so on.
Encapsulation: each layer wraps the data from the layer above with the header it needs for its own job.
| Layer | Unit | What it adds | In this example |
|---|---|---|---|
| Application | Message | HTTP request → encrypted into TLS records | GET /video |
| Transport | TCP segment | Source and destination ports, sequence number, ACK number, checksum | 51000 → 443 |
| Network | IP packet | Source and destination IPs, TTL, protocol number (TCP = 6) | 192.168.1.20 → 192.0.2.10, TTL 64 |
| Link | Frame | Source and destination MACs, error detection (FCS) | Laptop MAC → router MAC |
- Size limit: one frame is at most 1500 B (MTU). So TCP splits the data into pieces no larger than the MSS (usually 1460 B). Large data becomes many packets, and each may take a different path.
- Physical layer: turns the frame's bits into a signal and sends it. Wi-Fi uses radio waves, copper Ethernet uses electricity, and fiber uses light.
7. Link 1: laptop → router (Wi-Fi)
Picture several people in one room sharing a single walkie-talkie channel. You first listen for whether anyone is talking, and even when it is quiet you don't start right away: you count for a moment first. That cuts down on two people starting at once. This rule is CSMA/CA.
The wireless channel is a shared medium, so it uses CSMA/CA.
- Listen for whether the channel is free → even if it is, wait a random backoff → transmit → the AP sends an ACK (retransmit if it doesn't arrive).
- If there is a hidden terminal problem, reserve the channel first with RTS/CTS.
A home router is an AP + switch + router + DHCP server + firewall bundled into one product.
- A wireless frame received by the AP is handed to the router function inside the box (wireless frame → Ethernet frame conversion).
- For a wired PC, the switch looks up its MAC address table and forwards only to that port. For an unknown MAC it sends to every port.
8. Router: firewall + routing + NAT
Think of a company's main phone number. From the outside there is one number, but the operator writes down in a log "extension 20 made this call" and, when the reply comes, routes it back to that extension. The main number is the public IP, the extension is the private IP and port, and the operator's log is the NAT translation table.
- Check the frame FCS → strip the frame and take out the IP packet.
- Check the firewall rules (outgoing traffic is usually allowed).
- Routing: the destination 192.0.2.10 is outside the home LAN → default route = toward the ISP.
- NAT (more precisely NAPT, which rewrites ports too)
- TTL 64 → 63.
- Build a new frame for the outgoing link. Destination MAC = the next device on the ISP side (also learned through ARP or similar).
9. Link 2 onward: ISP → internet → server side (repeated at every router hop)
A box arriving at a sorting center has its outer label torn off. The center looks only at the final address inside, checks the dispatch sheet ("that region goes on that truck"), and puts on a new label for the next center. The dispatch sheet is the forwarding table, and passing one center is a hop.
At every router:
- Check the frame FCS. If it is corrupted, drop it (TCP retransmission recovers it later).
- Strip the frame and take out the IP packet.
- Destination IP → find the longest matching prefix in the forwarding table (longest prefix match) → next router.
- Decrease TTL by 1. If it hits 0, drop the packet and send ICMP Time Exceeded to the source (this stops packets from looping forever).
- Build a new frame for the outgoing link (destination MAC = the next device).
- Routing: deciding and maintaining path information. The result is the routing table.
- Forwarding: actually passing a packet to the next device by looking at that table.
- Routing protocols build the table: something like OSPF inside an ISP, BGP between ISPs.
Also:
- Intermediate routers don't look at application data (only up to the link and network layers). With TLS they couldn't read it anyway.
- ISPs connect directly, through an upstream provider, or by exchanging at an IXP. Overseas traffic rides the backbone and submarine cables.
- When a router queue fills up, packets are dropped → congestion. Time spent waiting in queues adds to the delay.
- If a link along the way has a smaller MTU, the packet is fragmented, or path MTU discovery is used to send small packets from the start.
- Packet switching: many people's packets share a link. That is why delay and throughput to the same server vary from moment to moment.
10. Server side: arrival + decapsulation + processing
The receiver opens the boxes one at a time from the outside. Is the outer label for this house, is the next box addressed to me, which room (port) is it for, and finally the item comes out. That is decapsulation.
Data center router → firewall → a load balancer hands it to one of several servers.
Decapsulation: frame → IP packet → TCP segment → application
- Link: is the destination MAC mine, check the FCS → take out the IP packet.
- Network: is the destination IP mine → look at the protocol number and pass it to TCP.
- Transport: find the matching socket by (source IP and port, destination IP and port) → reorder and send ACKs → hand the bytes to the web server program on 443.
- TLS decryption → application: parse the HTTP request.
The web server program processes it (database queries and so on) and builds the HTTP response: 200 OK, Content-Type, body (video data).
11. Response: the same road in reverse
The reply is packed the same way. The truck route back may differ from the one going out, though.
- The response is also encapsulated like steps 4 to 9 → crosses the hops and arrives at the router's public IP 203.0.113.5 : 40001. The path back can differ from the path out.
- The router looks up the NAT translation table, rewrites the destination back to 192.168.1.20 : 51000, and delivers it to the laptop.
- Laptop decapsulation: frame → packet → TCP
- Reassemble in order, ACK what arrived, get missing pieces retransmitted.
- Flow control: limit how much is sent so the receiver's buffer (receive window) doesn't overflow. Details in Flow control.
- Congestion control: when loss and delay suggest the network is clogged, slow down. Details in Congestion control.
- TLS decryption → the HTTP response goes up to the browser.
12. Browser: turning it into a page
Check the HTTP status code first: 200 success, 404 not found, 403 forbidden, 500 server error.
Parse the HTML → request CSS, JavaScript and images → render and show the page.
- Additional requests reuse the same TCP and TLS connection (keep-alive; HTTP/2 runs several requests at once over one connection). So steps 1 to 5 aren't repeated.
- Fetched resources are stored in the web cache.
Video is streaming. It plays while downloading instead of after the whole file arrives (with a little kept in a buffer).
- Adaptive streaming: segments are prepared in advance at 1080p/720p/480p, and the player picks the quality of the next segment from the recent download speed and buffer level. When things slow down it lowers the quality so playback doesn't stall.
13. Closing the connection
Hanging up a call also goes "I'm going to hang up" → "OK" → "I'll hang up too" → "OK", with each side announcing its own end. That is the 4-way close with FIN and ACK exchanged twice.
- After a while of no use, or when the tab is closed, TCP closes: FIN → ACK, FIN → ACK (4-way). The order is in Connection release.
- The side that closes first waits briefly in TIME_WAIT (to clean up late packets).
- The router's NAT translation table entry is also removed after a timeout.
What changes on each link vs what stays
| Header | Changes | Stays |
|---|---|---|
| Link | Source and destination MAC (new frame per link) | |
| IP | TTL (−1 per hop), source IP (once, at NAT) | Destination IP |
| TCP | Source port (once, at NAT) | Destination port 443 |
| Application | HTTP encrypted with TLS (unreadable to middleboxes) |
14. When using a VPN
It is like putting a letter, envelope and all, inside another envelope and mailing it to a "forwarding office". The mail carrier only sees the office address on the outer envelope, and the office opens it and mails the inner letter on to the real recipient. To the recipient, the letter seems to come from the office. The outer envelope is the outer IP and UDP headers, the office is the VPN server, and the letter inside is the encrypted original packet.
The purple band between the laptop and the VPN server is the tunnel. Gray marks what middleboxes can't read.
How to read the diagram
- Top: laptop → router → ISP router → VPN server → web server. The purple band between the laptop and the VPN server is the tunnel.
- Bottom box: on the tunnel links, the entire original packet is encrypted inside the outer IP and UDP headers (gray = the part middleboxes can't read).
- After the VPN server, the outer shell is gone and only the original packet continues.
VPN (Virtual Private Network): encrypting your whole packet, putting it inside another packet (one more layer of encapsulation), and sending it to the VPN server. That path is the tunnel.
Connection setup
- The VPN client exchanges keys with the VPN server (198.51.100.7) → a virtual network interface (
utun,tun0) appears and gets the virtual IP 10.8.0.2. - The routing table changes: the default route goes into the tunnel (full tunnel). Sending only the company range through the tunnel is a split tunnel.
- DNS also switches to the VPN's DNS server. If it doesn't, DNS queries go out outside the tunnel, which is called a DNS leak.
When sending
- Original packet: 10.8.0.2 → 192.0.2.10 : 443 (HTTP encrypted with TLS inside)
- The routing table sends it to the tunnel interface → the VPN client encrypts the whole packet.
- New headers go on the outside: UDP (→ 51820, WireGuard as an example) + IP (192.168.1.20 → 198.51.100.7)
- After that it is the usual path: ARP → router → NAT (only the outer source changes) → ISP router hops.
Who sees what
- Middleboxes: only the outer header. The router and the ISP know only that you are talking to a VPN server; they can't see the real destination (192.0.2.10) or the content.
- VPN server: strips the outer header and decrypts to recover the original packet → NAT rewrites the source 10.8.0.2 → 198.51.100.7 → sends it over the regular internet to the web server.
- Web server: source = the VPN server's IP. Your real IP and location are hidden.
Caveats
- There is no VPN encryption on the VPN server → web server leg. With HTTPS, TLS is still there (inside the tunnel it is VPN + TLS, double encryption).
- The VPN company sees all your destinations. Your trust just moves from the ISP to the VPN company.
- The extra headers mean less data per packet (MTU), and the detour adds delay.
- A company VPN has a different purpose: getting into the private network behind the VPN server (10.x servers).
15. Connecting over SSH
You type as if you were sitting in front of the remote computer, but even if the line in between is tapped, nothing leaks. On the first call you check the other side's voice (host key), and you prove who you are by signing with your key (private key). The voice is the fingerprint of the server's host key, and the key is your private key.
The top shows the message order between the laptop (ssh) and the server (sshd); the bottom shows the packet for a single keystroke.
How to read the diagram
- Top sequence: the message order between the laptop (ssh) and the server (sshd). They appear one at a time in number order. From ④ on, the lock = encrypted.
- Bottom: the packet when you press one key after the connection is set up. The path and hops are the same as the web request; only the destination port is 22.
SSH (Secure Shell): a protocol for connecting to a remote computer with encryption and running commands. Default port 22.
Telnet: the same kind of remote access with no encryption (port 23). Passwords and commands travel in plaintext, so it is unsuitable for remote access over the internet.
When you type ssh user@server.example.com
- DNS: server.example.com → IP (same as step 2)
- ARP, gateway, NAT and hops (same as steps 3 and 7 to 9). Destination port 22.
- TCP 3-way handshake (→ 22)
- Version exchange: each side sends one line
SSH-2.0-OpenSSH_…in plaintext. - Algorithm negotiation: exchange lists of key exchange, cipher and MAC methods and pick one of each.
- Key exchange: both sides compute the same session key with ECDH (curve25519 or similar). The server signs with its host key → from here on everything is encrypted.
- Host key check: the laptop compares against the fingerprint in
~/.ssh/known_hosts.- The first time, it asks "Are you sure you want to continue connecting?" and saves the key on yes.
- If it differs from the saved one, it warns (possible man-in-the-middle attack, server reinstall, etc.).
- User authentication
- Public key: your public key is in the server's
~/.ssh/authorized_keys, and the laptop proves itself by signing with the private key. The private key never leaves. Hands-on in SSH Key Authentication. - Password: the channel is already encrypted, so it doesn't leak in plaintext.
- Public key: your public key is in the server's
- Open a channel + start a shell: session channel → pseudo-terminal (pty) → a login shell starts on the server.
- Every keystroke: key input → SSH encrypts → TCP 22 → hops → the server's sshd decrypts → passed to the shell → the screen output (including the echo of the typed character) comes back encrypted.
A walkthrough of steps 4 to 8 from the server and client files' point of view is in How an SSH Server and Client Connect.
Reaching a PC behind NAT
To ssh from outside into a PC behind the home router, the router needs port forwarding (public IP:22 → 192.168.1.20:22). For connections going out from inside, the NAT translation table creates entries on its own, but packets coming in first from outside have no entry in the table and are dropped. Another way is to skip opening ports and run SSH over an overlay network such as Tailscale.
SSH tunnel
Carrying another TCP connection inside the SSH connection (ssh -L 8080:localhost:80 server). The principle is the same as a VPN: one more layer of encapsulation.