How the Web Works
Year 8 · The web · IGCSE Computer Science 5.1 · IGCSE ICT 21

How the Web Works

In one line

You type an address. Your browser finds the right computer, asks it for a page, gets back a text file, and draws it. Everything on this page is one of those four steps, zoomed in.

Fourteen stops, in the order it really happens. Each has a short explanation and something to try. Read one stop at a time.

1

The internet and the web are not the same

The internet is the network: cables, routers, Wi-Fi, and the rules for moving data between any two computers on Earth. The web is one thing that runs on it: pages, written in HTML, linked together, fetched with HTTP. Email, video calls, games and app updates all use the internet without being the web.

The internetcables, fibre, routers, Wi-Fi, and the rules (IP, TCP) that move packets anywhere The webpages · HTML · HTTPEmailSMTP · IMAPVideo callsUDP · real timeGamesUDP · serversApp updatesHTTPS downloads Services that use the internet (there are many more)
"Is Wi-Fi the internet?" No: Wi-Fi is a way to join a local network without a cable. The internet is what that network connects to.
?Why it matters

When the Wi-Fi light is on but nothing loads, the local network is fine and the internet link is down. When a page says 404, the internet worked perfectly and the web server simply has no such page. Knowing which layer failed is half of fixing it.

2

The URL: an address in parts

A URL (uniform resource locator) is the full address of one thing on the web. It has parts, and each part answers a different question: which rules, which computer, which page, with what details.

▶

Take any URL apart

e.g.Reading the domain

Read a domain name from the right. uk is the country code. co.uk is "companies in the UK". bbc.co.uk is the BBC's name inside that. www is a subdomain, a label the BBC chose for its web server; many sites no longer use it. Spain's code is .es; .com, .org and .net belong to no country.

3

DNS: turning a name into a number

Computers find each other by IP address, a number like 151.101.0.81. People remember names. DNS (the domain name system) is the phone book that turns one into the other, and nobody holds the whole book: it is split between thousands of servers and cached everywhere.

▶

Watch one lookup happen

  1. Browser cacheHave I looked this up in the last few minutes? No.
  2. Operating system cache, then the resolverAsk the resolver my router gave me (the ISP's, or 8.8.8.8): "what is www.bbc.co.uk?"
  3. Root serverThe resolver asks a root server. Answer: "I don't know, but the .uk servers do. Here they are."
  4. .uk server"I don't know www.bbc.co.uk, but here are the servers responsible for bbc.co.uk."
  5. bbc.co.uk's own (authoritative) server"www.bbc.co.uk is 151.101.0.81. You may remember that for 300 seconds."
  6. Answer, and cache itThe resolver tells the browser, and both remember it for the time-to-live (TTL). The next lookup takes one step.

All six steps take about 50 milliseconds the first time.

★Remember

DNS answers come with a time-to-live. That is why a website that moves to a new address can take "up to 24 hours" to work for everyone: old answers are still sitting in caches until they expire.

!Watch out

If an attacker poisons a resolver's cache with a wrong answer, you type the right name and land on a fake site. That is pharming, and it is why HTTPS checks the certificate matches the name, not just the address.

4

Packets: how anything crosses the internet

Nothing travels as one piece. The request, and later the page, are cut into packets of about 1,500 bytes. Each carries the sender's and receiver's IP addresses and a sequence number. Routers pass each one along, hop by hop, choosing a route each time. They can arrive out of order or get lost; TCP puts them in order and asks again for the missing ones.

▶

Send a message as packets

Cut into packets, each with a header

Arriving at the server, in the order the routes delivered them

Reassembled by sequence number

The TCP handshake, before any data

  1. SYNBrowser: "Hello, I'd like to talk. My numbering starts at 1000."
  2. SYN-ACKServer: "Hello back. Got your 1000. My numbering starts at 5000."
  3. ACKBrowser: "Got your 5000. Let's go." Now data flows, every byte numbered and acknowledged.

Why not just send it in one go?

  • A lost piece costs one small resend, not the whole file.
  • Many conversations share one cable fairly, packet by packet.
  • Packets can take different routes round a broken link.
  • The receiver can start work before the whole thing arrives.
5

HTTP: the request and the response

Once connected, the browser sends a request: plain text, a few lines. The server replies with a response: a status line, some headers, and the page. HTTP (hypertext transfer protocol) is nothing more than the agreed shape of those two messages.

▶

Be the browser, talk to a tiny server

This toy holds a pretend website with four addresses. Ask for one and see exactly what goes each way.

MethodPath
Request: browser → server
Response: server → browser

CodeMeansWhat you see
200OKThe page.
301Moved permanentlyThe browser quietly asks the new address instead. Search engines update their index.
403ForbiddenThe server knows the page but you may not have it.
404Not foundThe internet worked; the server has no such page.
500Server errorSomething broke on their side. Nothing you did.
e.g.GET and POST

GET asks for a page and carries any details in the URL (?q=cats). POST sends data in the body of the request: a login form, a comment, an upload. That is why pressing Back after a POST asks "resubmit the form?": the browser would be sending the data again.

6

HTTPS: the padlock

Plain HTTP is a postcard: every router on the way can read it. HTTPS puts the same conversation inside an encrypted envelope (TLS) and checks that the server is who it claims to be. The padlock means those two things, and only those two things.

▶

The handshake, step by step

  1. Client helloBrowser: "I speak these encryption methods. Here is a random number."
  2. Server hello and certificateServer: "Let's use this method. Here is my certificate: my public key, my domain name, signed by a certificate authority you already trust."
  3. Check the certificateBrowser checks the signature against the authorities built into it, and that the name on it is www.bbc.co.uk. Wrong name or bad signature: a red warning page.
  4. Agree a secretBoth sides use key-exchange maths (Diffie–Hellman) to arrive at the same fresh secret key. A listener who saw every message still cannot compute it.
  5. Encrypted from hereEverything after this, the request, the page, the cookies, is encrypted with that key (fast symmetric encryption, AES). The padlock appears.

The padlock means

  • Nobody between you and the server can read or change the conversation.
  • The server holds a certificate for this exact name, issued by an authority the browser trusts.

The padlock does not mean

  • The site is honest. Scammers get certificates too; the padlock just means it is really their fake site.
  • The site keeps your data safely once it arrives.
  • Your own computer is clean.
7

HTML: what is on the page

The response body is a text file written in HTML. Tags label each piece of content: this is a heading, this is a paragraph, this is a link to there, this is a picture called that. The browser reads the labels and builds a tree, the DOM. HTML is not a programming language: it describes, it does not compute.

▶

Write HTML, see the page and the tree

What the browser draws

The tree the browser built (the DOM)

    ★Remember

    Elements nest like boxes in boxes. Close the inner one before the outer one. Every image needs alt text: it is what a screen reader says, and what shows if the file is missing.

    !Try breaking it

    Delete the closing </strong> in the toy and watch the bold spread to everything after it. A missing closing tag is the number-one HTML bug.

    8

    CSS: how it looks

    CSS (cascading style sheets) is a list of rules. Each rule picks some elements (the selector) and sets properties: colour, size, spacing. The browser matches every rule to the tree. One stylesheet can restyle a thousand pages, which is the point of keeping looks out of the HTML.

    ▶

    Style the page from stop 7

    Same HTML, with your CSS

    Try: body { background: #FFF3D4; } or h1 { text-align: center; } or li { list-style: square; }

    ▶

    The box model: every element is a box

    From the inside out: content, padding (space inside the border), border, margin (space outside). Drag the sliders and watch the total width.

    e.g.Three ways to attach CSS

    External: <link rel="stylesheet" href="styles.css"> in the head, one file for every page (best). Internal: a <style> block in the head, for one page. Inline: style="…" on one element. If they disagree, inline wins, then internal, then external. The ICT exam asks exactly this.

    9

    JavaScript: what it does

    The third language is the only one the browser can run as a program. JavaScript waits for events (a click, a key, a timer, data arriving) and changes the tree: new text, new elements, new styles. Every button on this page is JavaScript doing that.

    ▶

    Ten lines that change the page

    The code behind the button
    <button id="go">Click me</button>
    <p id="out">Not clicked yet</p>
    
    <script>
      const button = document.getElementById("go");
      const out = document.getElementById("out");
      let count = 0;
      button.addEventListener("click", function () {
        count = count + 1;
        out.textContent = "Clicked " + count + " times";
      });
    </script>

    And here it is, running

    Not clicked yet

    Typing here runs: h1.textContent = input.value, and the preview in stop 7 changes as you type.

    ★The three languages in one line

    HTML is what is on the page. CSS is how it looks. JavaScript is what it does. Python never runs in the browser: when a site "uses Python", the Python runs on the server and sends back ordinary HTML.

    10

    How the browser draws it

    Between "file received" and "page on screen" the browser does six jobs, always in the same order. Knowing them explains why some pages flicker, why a slow script freezes everything, and what "layout" means when a developer says it.

    ▶

    The rendering pipeline

    1. Parse the HTML into the DOMTags become a tree of elements. Scripts met on the way are run immediately, which is why scripts go at the end of the body.
    2. Parse the CSS into rulesEvery stylesheet and style block becomes a list of selector → properties.
    3. Match rules to the treeFor each element, work out every rule that applies and resolve the winner for each property (the cascade). Hidden elements drop out.
    4. LayoutWork out the size and position of every box, top to bottom, using the box model. Change one width and everything below may move.
    5. PaintDraw text, colours, borders and images into layers of pixels.
    6. CompositeStack the layers on the screen. Animations that only move or fade a layer skip layout and paint, which is why they are smooth.
    ?Why a page can freeze

    JavaScript runs on the same thread that lays out and paints. A script that takes two seconds stops the page responding for two seconds. Good pages do heavy work in small pieces, or in a background worker.

    11

    Cookies and staying logged in

    HTTP has no memory: every request is a stranger. So after you log in, the server sends a cookie, a small text note with a random session ID, and your browser sends it back with every later request. The server looks the ID up and knows it is you. Close the tab, the cookie is still there; delete cookies, and you are a stranger again.

    ▶

    A pretend login

    What the server sent after login
    (nothing yet)
    What the browser now sends with every request
    GET /inbox HTTP/1.1
    Host: mail.example.com
    (no cookie: the server sees a stranger)

    You are not logged in.

    Kinds of cookie

    • Session: deleted when the browser closes.
    • Persistent: kept until an expiry date. "Remember me."
    • Third-party: set by an advert on the page, not the site itself. Used to follow you between sites; this is what the consent banners are about.

    Keeping it safe

    • HttpOnly: scripts on the page cannot read the cookie.
    • Secure: only ever sent over HTTPS.
    • Short expiry, and a new ID at login, limit the damage if one is stolen.
    12

    Where the page lives: hosting, domains, CDNs

    A web server

    A computer that is always on, running web server software (nginx, Apache) that waits for requests and sends files back. It could be a Raspberry Pi on a desk or one of ten thousand machines in a data centre. Hosting companies rent you space on theirs.

    A domain name

    Rented by the year from a registrar. You then point it at your server's IP address in DNS. Nobody owns .com; a registry runs each top-level domain and registrars sell names under it.

    A content delivery network

    Big sites copy their files to thousands of servers around the world. DNS sends each visitor to the nearest copy, so the image comes from Madrid rather than Seattle. Faster, and no single server to overload.

    Static or dynamic

    A static site is files on disk, the same for everyone: fast, cheap, safe. A dynamic site builds each page when asked, often with Python, PHP or Node.js, from a database: your feed, your basket, your inbox.

    BrowserHTML + CSS + JS Web servernginx / Apacheruns Python / PHP / Nodebuilds the HTML Databaseusers, posts, prices CDNimages, CSS, video, near you GET /inbox + cookie 200 OK + your HTML SQL the page's images and CSS, fetched separately
    13

    Search engines, and being found

    Google does not search the web when you press Enter. It searched it already, continuously, and you search its index.

    1. CrawlPrograms called crawlers follow every link they can find and fetch the pages, billions a day.
    2. IndexEach page's words are added to a giant index: this word appears on these pages, in these positions, with this importance.
    3. RankFor your query, pages are scored: do the words match, how many good sites link here (the original PageRank idea), is it fast, does it work on phones, is the content fresh and original.
    4. AnswerThe top results come back in a fraction of a second, from the index, not the web.
    e.g.Why the title and headings matter

    The <title> and <h1> carry the most weight in the index, which is why a page about binary should say "binary" in both, and why clickbait titles exist.

    !Watch out

    Top of the results is not the same as true. Adverts sit above results and are labelled. Judge a page by who wrote it, when, and whether you can check it elsewhere.

    14

    A good page: fast, accessible, honest

    Accessible to everyone

    • Alt text on every image.
    • Real headings in order (h1, then h2…), so a screen reader can jump by them.
    • Enough contrast between text and background.
    • Everything reachable with the keyboard alone, with a visible focus.
    • Text that can be resized without breaking.

    Fast

    • Small images, compressed, in modern formats.
    • CSS in one file, scripts at the end or marked defer.
    • Cache headers so repeat visits load from disk.
    • Fewer requests: every file is a round trip.

    Honest with data

    • HTTPS everywhere.
    • Ask before tracking (cookie consent), and keep the choice.
    • Collect only what the page needs, and say what for.
    A–Z

    The words

    ✓

    Check yourself

    0 of 10 answered