Skip to content
Tutorials Center
My learning

Topics

Lesson 70 of 79 ยท How the Web Works and Real-World Projects

What Happens When You Type a URL

Follow one web request from the address bar to the screen: URL parsing, DNS, ARP, routing, NAT, TCP, TLS, HTTP and rendering, with a live Python timeline simulation.

"What happens when you type a URL into a browser and press Enter?" is a famous interview question because the honest answer touches almost everything in networking. In about a tenth of a second, your computer finds an address, discovers a path, builds a reliable connection, agrees on encryption keys, asks for a page and turns the reply into pixels.

This lesson is the capstone of the theory chapters. Each step links back to the lesson where it is explained in detail, so you can use it as a map. We will follow a request for https://www.example.org/docs/intro.html from a laptop on home Wi-Fi.

sequenceDiagram
    participant B as Browser
    participant R as Home router
    participant D as DNS resolver
    participant S as Web server
    B->>B: 1. parse URL, check caches
    B->>D: 2. DNS: www.example.org?
    D-->>B: A 203.0.113.25
    B->>R: 3. ARP for gateway (if not cached), send via router
    B->>S: 4. TCP SYN
    S-->>B: SYN-ACK
    B->>S: ACK
    B->>S: 5. TLS ClientHello
    S-->>B: ServerHello, certificate, Finished
    B->>S: 6. HTTP GET /docs/intro.html
    S-->>B: 200 OK, HTML
    B->>B: 7. parse HTML, fetch CSS/JS/images, render

The main phases of one page load. Each arrow crosses the layers of the TCP/IP stack.

Step 1: Parse the URL and check local caches

The browser first decides whether you typed a search or a URL. A URL splits into parts:

  • scheme https (which protocol and default port, 443),
  • host www.example.org,
  • port (default unless given),
  • path /docs/intro.html, plus optional query ?x=1 and fragment #top (the fragment never leaves the browser).

Before touching the network the browser checks what it already knows: its HSTS list (does this site demand HTTPS?), its HTTP cache (is a fresh copy stored? see caching), existing open connections it can reuse, and its DNS cache. A warm browser can skip several of the steps below.

Step 2: DNS finds the IP address

Applications use names but packets need addresses, so the browser asks the operating system to resolve www.example.org. The OS checks its own cache and the hosts file, then sends a DNS query to its configured recursive resolver (usually from DHCP, often the home router or the ISP). If the resolver has the answer cached, it replies at once. If not, it walks the hierarchy: a root server points to the .org servers, which point to the authoritative servers of example.org, which return the address. The answer comes with a TTL that says how long everyone may cache it. Modern resolvers may be reached over encrypted DNS and the answer may include both an IPv4 (A) and an IPv6 (AAAA) record; the browser may race both.

Step 3: Finding the next hop (routing, ARP, NAT)

Now the system has a destination IP, 203.0.113.25. Its routing table says that this address is not on the local subnet, so the packet must go to the default gateway (the home router). To build the Ethernet frame the laptop needs the gateway's MAC address, which it gets with ARP (or from its ARP cache). The frame has the gateway's MAC as the Layer 2 destination, but the destination IP stays the server's.

At each router, the same cycle repeats: look up the destination in the routing table (longest-prefix match), decrement the TTL, and send it to the next hop in a new frame with new MAC addresses. Between networks, routers use protocols such as OSPF inside an organization and BGP between them. At your home router, NAT rewrites the private source address (such as 192.168.1.20) to the router's public address and remembers the mapping, so replies find their way back.

Step 4: TCP connection

Browsers use TCP (or QUIC for HTTP/3, see QUIC) to get reliable, ordered delivery. The laptop picks an ephemeral source port such as 51044 and runs the three-way handshake: SYN, SYN-ACK, ACK. This costs one round trip before any data is sent. Both sides agree on starting sequence numbers, the MSS and window scaling. Afterwards, TCP's reliability, flow control and congestion control manage the transfer; a brand-new connection starts slowly and speeds up (slow start).

Step 5: TLS handshake

Because the scheme is https, the connection is secured before any HTTP is sent (TLS). In TLS 1.3 the browser sends a ClientHello with the server name (SNI), supported ciphers, a key share and the application protocols it offers (ALPN, for example h2 and http/1.1). The server replies with its choice, its own key share and its certificate. The browser checks that the certificate chains to a trusted authority, matches the host name and is not expired; both sides derive session keys and exchange Finished messages. This costs one more round trip in TLS 1.3 (two in TLS 1.2), and returning visitors can resume faster.

Step 6: HTTP request and response

Finally the browser sends the HTTP request, encrypted inside TLS:

TEXT
GET /docs/intro.html HTTP/2
Host: www.example.org
Accept: text/html
Accept-Encoding: gzip, br
Cookie: session=...            (only if the browser has cookies for this site)

The request may first hit a CDN or reverse proxy / load balancer near the user, which either answers from its cache or forwards the request to an application server. That server runs code, maybe queries a database and builds a response:

TEXT
HTTP/2 200
content-type: text/html; charset=utf-8
content-encoding: br
cache-control: public, max-age=300

<!doctype html> ...

The status code (200, a redirect such as 301, an error such as 404) tells the browser what to do next. A redirect restarts the process for a new URL, which is why avoiding redirect chains makes pages faster.

Step 7: Rendering, and many more requests

The HTML is only the beginning. The browser parses it while it arrives, discovers CSS, JavaScript, fonts and images, and requests each one, often from other hostnames (so more DNS, TCP and TLS work), reusing connections where possible. With HTTP/2 and HTTP/3 many requests share one connection (HTTP evolution). It builds the DOM and the style tree, runs scripts, lays out the page and paints pixels. JavaScript may then fetch more data in the background with fetch, or open a WebSocket.

Where does the time go?

Network time is dominated by round trips, not bandwidth. A cold load costs roughly: DNS lookups, one RTT for TCP, one for TLS, one for the HTTP request, plus server think time. That is why CDNs bring servers closer (smaller RTT), why connections are reused, why HTTP/3 and TLS 1.3 shave round trips, and why caching is the cheapest optimization of all.

Python A timeline of one page load (cold, warm DNS, warm connection)

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

A second look: what each layer adds

As the data goes down the stack, every layer wraps it with its own header (see encapsulation). The next example builds the stack for our request and prints the size of each layer.

Python Wrap an HTTP request layer by layer

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. Before any packet is sent to a web server, which lookup must normally succeed first?

    The browser needs the server's IP address, and DNS provides it. ARP resolves only the next hop on the local network, which is the gateway for a remote server.
  2. 2. When your laptop sends a packet to a server on another network, whose MAC address is in the destination field of the Ethernet frame?

    The frame only needs to reach the next hop, the gateway. The destination IP address remains the server's.
  3. 3. How many round trips does a fresh HTTPS connection with TLS 1.3 need before the HTTP request can be sent?

    The TCP three-way handshake takes one round trip and the TLS 1.3 handshake one more, so the request goes out on the third.
  4. 4. What does the home router's NAT do on the way out?

    NAT translates the source so that many private hosts can share a public address, and uses the table to send replies to the right device.
  5. 5. Why does a browser often reuse an existing connection for a second page on the same site?

    Each new connection costs several round trips; reusing one removes that setup time.

Summary

  • The browser parses the URL and checks its caches (HSTS, HTTP cache, DNS cache, open connections) before using the network.
  • DNS turns the host name into an IP address; routing and ARP choose the next hop (the gateway), and each router forwards the packet hop by hop, with NAT at the home edge.
  • TCP gives a reliable connection after a three-way handshake; TLS adds encryption and server authentication; HTTP carries the request and response, often via a CDN or load balancer.
  • The HTML triggers many more requests, then the browser builds and paints the page.
  • Latency is dominated by round trips, so caching, connection reuse, CDNs, TLS 1.3 and HTTP/3 make pages faster.

You now have the whole stack in your head. Put it into practice with the first project: Project: Subnet Planner.