Part 1 · Foundations
How the Internet works: what happens when you open a URL
Course contents
This lesson assumes you know nothing about networks. By the end of it you will be able to explain, in plain words, what happens between typing https://example.com into a browser and seeing the page. Every word you need is introduced here, one at a time, and every later lesson zooms into one part of this picture.
You only need a terminal on a Linux machine (a VM or WSL is fine; see Set up the lab on the course page). Commands you run are in black boxes; the light boxes under them, labelled output, show what a real machine printed.
What a network is
A network is two or more devices connected so they can send each other data. Your home is a good example: your laptop, your phone and maybe a TV are all connected to one box, the Wi-Fi router. Together they form a small network that lives in one place, a local area network, or LAN.
On its own, a LAN only lets your own devices talk to each other. To reach a website, your home network connects to the network of your ISP (Internet service provider: the company you pay for Internet access). Your ISP’s network connects to other ISPs, to universities, to cloud companies and so on. The Internet is exactly that: tens of thousands of independent networks, owned by different organizations, connected to each other. A network of networks.
Data travels in packets
Everything you send over a network, a web page, a photo, a chat message, is just bytes. Networks don’t send those bytes as one long stream. They cut them into small pieces called packets, usually at most about 1,500 bytes each. A web page of 300 KB becomes a couple of hundred packets.
Every packet has two parts:
- a header: a few dozen bytes at the front with delivery information, such as where the packet comes from and where it is going. Think of the writing on an envelope.
- a payload: the piece of your data the packet carries. Think of the letter inside.
Each packet travels on its own. Two packets of the same page may even take different paths, arrive in a different order, or get lost on the way. Programs at both ends put the pieces back in order and ask again for anything that went missing. You will see exactly how in the TCP lesson.
Why packets and not one long connection? The old telephone network reserved a whole line for each call, even during silence (circuit switching). The Internet instead lets everyone’s packets share every cable, one after another (packet switching). It is far more efficient, and the price is that nothing is guaranteed: the network only makes a best effort to deliver each packet. Reliability is added on top, by software at the two ends.
Addresses: how a packet knows where to go
For a packet to arrive, it needs an address, just like a letter.
- IP address. Every device that talks on the Internet has one. The common kind, IPv4, is written as four numbers from 0 to 255 separated by dots, like
192.168.1.20or203.0.113.10. (There is a newer, longer kind, IPv6, which gets its own lesson.) The header of every packet contains the IP address of the sender and of the receiver. - Private and public addresses. Your laptop’s address at home is probably something like
192.168.1.20. That is a private address: it only means something inside your home, and thousands of other homes use exactly the same one. On the Internet, your home is known by a single public address that belongs to your router. The router translates between the two; this trick is called NAT and you will build it yourself in the routing lesson. - Port. One device runs many programs at once: a browser, a chat app, an update service. The IP address gets a packet to the right device; a port number gets it to the right program on that device, like an apartment number after a street address. Some ports are well known: web servers listen on port 443 for HTTPS and port 80 for plain HTTP.
- Names. People don’t remember
203.0.113.10; they rememberexample.com. The DNS (Domain Name System) is the Internet’s phone book: you give it a name and it gives you back an IP address. It has its own lesson.
Who’s who on a network
- Host: any device that runs programs and sends or receives data: a laptop, a phone, a server.
- Client and server: the client asks, the server answers. Your browser is a client; the computer that stores
example.comand sends it to you is a server. A “server” is just a computer running a program that waits for requests. - Router: a device that connects networks and passes packets from one to the next, each time choosing which way gets them closer to their destination. The Internet is held together by routers.
- Switch: a device that connects hosts inside one local network. It doesn’t connect networks; it just moves data between the machines plugged into it.
- Default gateway: the router a host sends a packet to when the destination is not on its own local network. At home, that is your home router.
The box your ISP gave you is usually several of these in one: a router (between your home and the ISP), a small switch (the cable ports on the back), a Wi-Fi access point (the same thing, over radio), and a few services that hand out addresses and answer DNS questions.
Protocols: rules for the conversation
Two programs can only understand each other if they agree on the format of their messages and on who says what, and when. That agreement is a protocol. HTTP, the protocol of the web, is simple enough to read:
client: GET /index.html HTTP/1.1 "please send me /index.html"
Host: example.com
server: HTTP/1.1 200 OK "here it is"
Content-Type: text/html
<html>...
Delivering a web page takes several protocols working together, each solving one problem:
| Problem | Protocol | Lesson |
|---|---|---|
| Move bits between two machines on the same cable or Wi-Fi | Ethernet, Wi-Fi | The local network |
| Get a packet across many networks to the right machine | IP | IPv4 |
| Get data to the right program, complete and in order | TCP (or UDP) | TCP and UDP |
| Turn a name into an IP address | DNS | DNS |
| Keep the conversation private and prove who the server is | TLS | TLS |
| Ask for a page and get it back | HTTP | HTTP |
These protocols are stacked in layers, each one using the one below it. The next lesson is about exactly that.
Speed: bandwidth and latency
Two different numbers describe how “fast” a connection is, and mixing them up is the most common mistake people make.
- Bandwidth is how much data a link can carry per second: the width of the pipe. It is measured in bits per second, so a “100 Mbps” plan carries 100 million bits per second. Files are measured in bytes, and one byte is 8 bits, so 100 Mbps is at most 12.5 megabytes per second. (That is why a “1 Gbps” connection downloads at about 125 MB/s at best.)
- Latency is how long one packet takes to arrive: the length of the pipe. The time there and back is the RTT (round-trip time), which is what
pingshowed you. - Throughput is what you actually get in practice. It is always less than the bandwidth.
Latency has a hard floor: nothing travels faster than light, and in a glass fiber light covers about 200,000 km per second. Tehran to Frankfurt is about 4,000 km, so a packet needs at least 20 ms to get there and 40 ms to come back, however much bandwidth you buy. Most of the time, waiting for round trips, not a lack of bandwidth, is what makes things feel slow. Remember this; it comes back in almost every lesson.
Two more words you will meet: jitter is how much the latency varies from one packet to the next (bad for calls and games), and packet loss is the share of packets that never arrive.
Putting it together: what happens when you open a URL
You now know every word in this story. You type https://example.com and press Enter:
- The browser reads the URL.
httpsmeans “the web, encrypted”, which by default uses port 443.example.comis the name of the server. - DNS turns the name into an address. The browser asks a DNS server “what is the IP address of
example.com?” and gets back something like203.0.113.10. (DNS lesson) - Your computer decides where to send the first packet.
203.0.113.10is not on your local network, so the packet goes to the default gateway, your home router. (Routing lesson) - The packet crosses your local network. Your laptop wraps the packet in a Wi-Fi or Ethernet frame addressed to the router’s network card. (The local network)
- Your router swaps addresses (NAT) so the packet leaves with your home’s public address, and hands it to your ISP.
- Router after router across the Internet. Each router passes the packet one step closer to the network where
203.0.113.10lives. How routers on the Internet know the way is the subject of the BGP lesson. The server you reach is often a copy of the site placed close to you by a CDN (a content delivery network). - A connection is set up. Your computer and the server exchange three short packets to agree to talk (the TCP handshake). (TCP lesson)
- Encryption is set up. A few more messages agree on encryption keys, and your browser checks the server’s certificate, a signed document that proves the server really is
example.com. (TLS lesson) - The page is requested and sent. The browser sends
GET /; the server answers200 OKand the HTML of the page, cut into packets that travel the whole way back. (HTTP lesson) - More requests follow. The HTML mentions images, styles and scripts, and the browser asks for each one, usually over the same connection.
All of that typically takes less than a second.
Words to remember
| Word | In one sentence |
|---|---|
| Network / LAN | Devices connected to exchange data; a LAN is one in a single place, like a home or an office. |
| Internet | Tens of thousands of independent networks connected to each other. |
| ISP | The company that connects your network to the rest of the Internet. |
| Packet | A small piece of data with a header (addresses) and a payload (the data itself). |
| IP address | The address of a device on the network, like 192.168.1.20; private inside your home, public on the Internet. |
| Port | A number that picks the program on a device: 443 for HTTPS. |
| DNS | The phone book: turns a name into an IP address. |
| Router / default gateway | Connects networks and forwards packets; the default gateway is the router a host sends everything non-local to. |
| Switch | Connects the devices inside one local network. |
| Protocol | The agreed rules and message format for a conversation. |
| Bandwidth / latency / RTT | How much per second / how long one packet takes / the time there and back. |