- Browserapp
- OS stackkernel
- NIChardware
- Home routerfirst hop
- ISP + internetmany hops
- Google networkedge + VPC
- VMOS + NIC
- Node appyour code
This chapter covers the first three stopslater chapters cover the rest of the trip
The example we follow
You open Kadé's website on your laptop at home. The page calls Kadé's API: a Node.js app running on a virtual machine (VM) called kade-api in Google Cloud (GCP). The call uses HTTPS. The full setup, with every address, is in chapter 0.
Wide by design - scroll it sideways.
In code, it starts with one line:
const response = await fetch("https://api.kade.lk/profile");
This asks the browser to get the /profile resource from the server named api.kade.lk, using HTTPS. Before anything can be sent, the browser and the operating system (OS) must know four values. Together they name one connection:
| Value | Example | Where it comes from | Why it matters |
|---|---|---|---|
| Source IP | 192.168.1.23 | Your laptopgiven by the home router when you join the WiFi | Where the reply goesthe server answers to this address |
| Source port | 52814 | The OSa free temporary port, picked per connection | Which program gets the replyyour laptop may have many open connections |
| Destination IP | 34.87.120.15 | DNS lookupturns api.kade.lk into an IP address | Which machine to reachrouters forward on this value |
| Destination port | 443 | The URL schemehttps:// means port 443 by default | Which program on that machinethe process listening on 443 |
Finding the server: DNS
Computers route by IP address, not by name. DNS (Domain Name System) is the internet's phone book: it turns api.kade.lk into an IP address. No single server knows every name, so the answer is found by walking a chain of servers, from the most general to the most specific.
1: the browser asks the resolver "where is api.kade.lk?". 2 to 4: the resolver asks the root, then the .lk servers, then the servers that own kade.lk. 5: the answer comes back. Every step keeps a copy (cache) for a set time called the TTL, so the next lookup is much faster.
Wide by design - scroll it sideways.
Writing the HTTP request
Now the browser knows where to send. Next it writes the message itself: the HTTP request. HTTP is plain text with a fixed shape: one request line, then headers, then an empty line (and a body, for requests like POST).
HTTP rides on TCP
HTTP only defines what the message says. It does not move anything by itself. The moving is done by TCP (Transmission Control Protocol). TCP makes delivery reliable and in order, using mechanisms like the three-way handshake, flow control and congestion control. Each of these gets a deep-dive chapter later.
HTTP
What you want to say.
"Give me /profile, here is my session."
TCP
The reliable courier that makes sure it arrives, complete and in order.
three-way handshakeflow controlcongestion control
Text becomes bytes
The network does not move text. It moves bytes. An encoder turns each character into its byte value. We usually write bytes in hexadecimal (base 16), so each byte is two characters from 00 to FF.
- G47
- E45
- T54
- space20
- /2F
- p70
- r72
- o6F
- f66
- i69
- l6C
- e65
- space20
- H48
- T54
- T54
- P50
- /2F
- 131
- .2E
- 131
- CR0D
- LF0A
The first line of the request: 23 characters become 23 bytes. CR LF (0D 0A) are the invisible “end of line” characters HTTP uses.
Here is the whole request as the raw bytes the OS receives, in the same layout the xxd tool prints: position on the left, bytes in the middle, readable characters on the right.
00000000: 4745 5420 2F70 726F 6669 6C65 2048 5454 GET /profile HTT00000010: 502F 312E 310D 0A48 6F73 743A 2061 7069 P/1.1..Host: api00000020: 2E6B 6164 652E 6C6B 0D0A 4175 7468 6F72 .kade.lk..Author00000030: 697A 6174 696F 6E3A 2042 6561 7265 7220 ization: Bearer 00000040: 6579 4A68 6247 6369 4F69 4A49 557A 4931 eyJhbGciOiJIUzI100000050: 4E69 4A39 0D0A 436F 6F6B 6965 3A20 7365 NiJ9..Cookie: se00000060: 7373 696F 6E5F 6964 3D38 6632 6139 3163 ssion_id=8f2a91c00000070: 0D0A 4163 6365 7074 3A20 6170 706C 6963 ..Accept: applic00000080: 6174 696F 6E2F 6A73 6F6E 0D0A 5573 6572 ation/json..User00000090: 2D41 6765 6E74 3A20 4D6F 7A69 6C6C 612F -Agent: Mozilla/000000a0: 352E 300D 0A0D 0A 5.0....
167 bytes in total. The first three (47 45 54) are “GET”. The dots on the right are line breaks (0D 0A), which have no printable form. With HTTPS, these bytes are encrypted by TLS before TCP sees them.
The browser hands off to the OS
The browser prepares the message, but it never puts anything on the network itself. It hands the bytes to the operating system's TCP/IP stack: the part of macOS, Windows or Linux that implements TCP, UDP, ICMP and IP. The OS also picks the source port. When the data is ready to go, the stack passes it to the NIC (Network Interface Card): the hardware that turns bits into signals, electrical pulses on a cable or radio waves in the air.
Wide by design - scroll it sideways.
Breaking data into chunks
Data cannot travel as one big blob. A 500-byte request or a 1 GB file is cut into many smaller chunks. Each chunk travels on its own and they are put back together at the destination. Say we have 4,000 bytes to send:
Chunk size is limited by the MSS (below). Sequence numbers count bytes. Real connections start from a random number; we start from 1 to keep it readable.
Wide by design - scroll it sideways.
Two limits decide the chunk size:
- MTU (Maximum Transmission Unit): the biggest packet a link can carry in one frame. On Ethernet and most WiFi this is 1,500 bytes.
- MSS (Maximum Segment Size): the biggest chunk of data one TCP segment can hold. It is what is left of the MTU after the IP and TCP headers.
Sizes in bytes, not to scale.
Wide by design - scroll it sideways.
Wrap 1: the TCP segment
Now each chunk gets wrapped, like putting a letter in an envelope. First, TCP adds its header. The result is called a TCP segment. The header holds the source port (52814), the destination port (443) and, most importantly, a sequence number.
Wide by design - scroll it sideways.
The sequence number is the heart of TCP's reliability. Chunks can take different paths and arrive out of order. The receiver uses the numbers to put them back in order, and to notice when one is missing:
| sent | seq 1 seq 1461 seq 2921 |
| arrived | seq 1461 seq 2921 seq 1 order mixed up on the way |
| rebuilt | seq 1 seq 1461 seq 2921 sorted by number, a gap would mean a lost chunk |
Wrap 2: the IP packet
Next, the IP layer wraps the TCP segment and adds the source IP (192.168.1.23) and destination IP (34.87.120.15). The result is an IP packet.
Wide by design - scroll it sideways.
Every router on the way reads the destination IP and decides which way to forward the packet next. No router knows the full path. Each one only picks the next step, called a hop. The source IP is what lets the server know where to send the response.
- Laptop
- Home routernext hop?
- ISP routernext hop?
- … more …next hop?
- Google edgenext hop?
- VM
Wrap 3: the frame
The last wrap adds physical addresses, called MAC addresses. Every network card has one, for example a4:83:e7:2b:91:0c. The result is a frame. The frame also gets a small error check at the end (FCS) so the receiver can spot damaged frames.
Wide by design - scroll it sideways.
The source MAC is your laptop's NIC. But what is the destination MAC? The server is not on your local network, so you do not know its MAC, and could not use it anyway. Instead, the destination MAC is your default gateway: the home router, the device that forwards traffic out of your network.
This leads to an important pattern. IP addresses describe the whole trip. MAC addresses only describe the current step:
| Hop | MAC addresses (frame) | IP addresses (packet) |
|---|---|---|
| Laptop → home router | a4:83:e7:2b:91:0c → 3c:84:6a:10:ee:01 | 192.168.1.23 → 34.87.120.15 |
| Home router → ISP router | router's WAN MAC → ISP router's MAC | your public IP → 34.87.120.15 |
| Every later hop | new pair every time | stays the same |
ARP, then onto the wire
The laptop knows the router's IP (192.168.1.1) from its network settings. But how does it learn the router's MAC? With ARP (Address Resolution Protocol). The laptop shouts a question to every device on the local network, and only the owner of that IP answers.
The laptop saves the answer in its ARP cache, so it does not ask again for every frame. ARP is like DNS for the local network: DNS maps a name to an IP, ARP maps an IP to a MAC.
Wide by design - scroll it sideways.
With the router's MAC filled in, the frame is complete. The OS hands it to the NIC, which sends it as physical signals:
WiFi
Radio waves through the air.
Ethernet
Electrical pulses on a copper cable.
Fiber
Pulses of light in a glass strand.
Where we are now
After all of this, the data has only reached your home router. We have covered roughly the first quarter of the trip.
- Browserapp
- OS stackkernel
- you are hereNIChardware
- Home routerfirst hop
- ISP + internetmany hops
- Google networkedge + VPC
- VMOS + NIC
- Node appyour code
Chapter 1: browser → NIC → first frame toward the routerstill ahead: routing, the GCP side, the server, the response
Everything above is unpacked, routed and repeated at every hop. The rest of these notes follow the frame from here to the Node app and back.
Summary
| # | Step | What happens | Done by | New terms |
|---|---|---|---|---|
| 1 | Name the target | fetch() gives a URL; four values define the connection | Browser | source/destination IP and port |
| 2 | Find the IP | Resolver walks root → TLD → authoritative | Browser, resolver | DNS, TTL, cache |
| 3 | Write the request | Method, path, headers, auth, cookies | Browser | HTTP |
| 4 | Pick a courier | HTTP is carried by TCP (and encrypted by TLS) | Browser, OS | TCP, TLS |
| 5 | Encode | Text turned into bytes | Browser | bytes, hexadecimal |
| 6 | Hand off | Bytes given to the OS, which picks the source port | OS | TCP/IP stack, NIC |
| 7 | Chunk | Data cut into pieces of at most 1 MSS | OS (TCP) | MTU, MSS |
| 8 | Wrap 1 | Add ports + sequence number | OS (TCP) | segment |
| 9 | Wrap 2 | Add source + destination IP | OS (IP) | packet, hop |
| 10 | Wrap 3 | Add source MAC + router's MAC | OS, driver | frame, MAC, default gateway |
| 11 | Find router MAC | Broadcast "who has 192.168.1.1?" | OS | ARP, ARP cache |
| 12 | Transmit | Frame sent as radio, electrical or light signals | NIC | physical medium |
Try it yourself
Each of these shows one step of this chapter on your own machine.
DNS answer
- What to look for: The IP the name resolves to. Run
dig +trace example.comto see the root → TLD → authoritative chain. - Runs on: macOS / Linux · Windows: nslookup example.com
- From section: 2. Finding the server: DNS
dig example.com +shortThe HTTP request and response headers
- What to look for: Lines starting with
>are what you sent (method, path, headers). - From section: 3. Writing the HTTP request
curl -v https://example.comText as bytes
- What to look for:
47 45 54is "GET". - Runs on: macOS / Linux
- From section: 5. Text becomes bytes
printf 'GET /profile' | xxdOpen TCP connections
- What to look for: Each line shows the four values: local IP:port and remote IP:port. Note the random local ports.
- Runs on: Linux · macOS: netstat -an -p tcp · Windows: netstat -an
- From section: 1. The example we follow
ss -tnYour IP and MAC
- What to look for:
inetis your IP,ether/ link address is your MAC. - Runs on: Linux · macOS: ifconfig · Windows: ipconfig /all
- From section: 10. Wrap 3: the frame
ip addrYour default gateway
- What to look for: The
defaultline shows your router's IP. - Runs on: Linux · macOS: netstat -rn · Windows: route print
- From section: 10. Wrap 3: the frame
ip routeYour ARP cache
- What to look for: The router's IP next to its MAC address.
- Runs on: macOS / Linux / Windows
- From section: 11. ARP, then onto the wire
arp -aThe MTU limit
- What to look for: 1472 + 8 (ICMP) + 20 (IP) = 1500 works. Try 1473: it fails because the packet no longer fits.
- Runs on: macOS · Linux: ping -M do -s 1472 · Windows: ping -f -l 1472
- From section: 7. Breaking data into chunks
ping -D -s 1472 1.1.1.1