How the internet works · Computer Basics
When you open a website, how does the page get from the other side of the world to your screen in under a second?
Course contentsWhy you need it
You use the internet every day, and almost every program you'll ever write talks to it.
Knowing the basic journey (addresses, names, packets, servers) helps you understand messages like "server not found", spot unsafe websites, and later build your own.
The intuition
The internet is a huge web of computers joined by cables, fibre and radio (Wi-Fi and mobile networks). Sending something across it works a lot like the post.
- Every device has an address, called an IP address, such as
203.0.113.7. Data uses it to find the right computer, the way a letter uses a street address. - Names are easier than numbers, so we use domain names such as
example.com. A service called DNS works like the contacts on your phone: you look up a name and get back the number. - Big things travel in small pieces. A page or a photo is cut into packets, each labelled with where it's going and a number. Routers pass packets along, hop by hop. Packets can take different roads and arrive out of order; your computer puts them back in order by their numbers and asks again for any that went missing.
- Browsers ask, servers answer. Your browser (Chrome, Safari, Edge…) sends a request: "Please send me this page." A server, a computer that is always on and waiting, sends the page back. The rules for this conversation are called HTTP.
A web address, or URL, has parts:
https:// | www.example.com | /pets/cats.html |
|---|---|---|
| how to talk (the protocol) | which server (the domain name) | which page on that server (the path) |
The s in https means the conversation is encrypted: nobody in between can read it or change it, and your browser shows a padlock. Never type a password on a page without it.
Definition
Internet
The internet is a global network of networks that lets computers anywhere exchange data.
IP address
An IP address is a number that identifies a device on a network so that data can be delivered to it.
DNS
DNS (the Domain Name System) translates domain names such as example.com into IP addresses.
Examples
Look up a name
Try it yourselfThis machine is a tiny DNS: a list of names and their addresses. Look up shop.net, then try a typo such as scool.edu and you'll get the same message a browser shows.
dns = {
"example.com": "203.0.113.7",
"school.edu": "198.51.100.20",
"shop.net": "192.0.2.55",
}
name = "school.edu" # change me 改这里
if name in dns:
print(name, "is at", dns[name])
else:
print("Server not found:", name)- L2The phone book: each name with its IP address.
example.com → 203.0.113.7 - L6The name to look up.
name = "school.edu" - L7Is the name in the book?
yes - L8Answer with its address.
school.edu is at 198.51.100.20
Cut into packets
Try it yourselfA message is cut into numbered pieces of 4 characters (real packets hold about 1,500 bytes). Make the message longer or change the size.
message = "See you at six" # change me 改这里
size = 4
number = 1
for start in range(0, len(message), size):
print("packet", number, "[" + message[start:start + size] + "]")
number = number + 1- L1The message to send.
message = "See you at six" - L2Each packet carries 4 characters.
size = 4 - L5Packet 1 gets the first four characters, space included.
packet 1 [See ] - L5The last packet holds what's left.
packet 4 [ix]
Back in order
Try it yourselfThe packets arrived as 3, 1, 4, 2. Thanks to their numbers, your computer can still rebuild the message.
arrived = [(3, "at s"), (1, "See "), (4, "ix"), (2, "you ")]
arrived.sort()
message = ""
for number, piece in arrived:
message = message + piece
print(message)- L1Packets in the order they arrived: (number, piece).
3, 1, 4, 2 - L2Sort them by number.
1, 2, 3, 4 - L5Join the pieces.
message = "See you at six" - L6The message is whole again.
See you at six
Common mistakes
The internet is more than the web
The web (websites in a browser) is one thing that runs on the internet. Email, video calls, online games and app updates all use the internet too.
A padlock means private, not trustworthy
HTTPS means nobody in between can read or change the data. A scam site can have a padlock too, so also check that the domain name is exactly right: examp1ebank.com (with the digit 1) is not examplebank.com.
"The cloud" is someone else's computer
Files "in the cloud" are stored on servers in big buildings called data centres, and you reach them over the internet. No internet, no cloud files, unless they were also saved on your device.
Quick quiz
1. What does DNS do?
Show the answer
Answer: A
DNS is the internet's phone book: name in, IP address out.
2. In https://www.example.com/news/today.html, which part is the domain name?
Show the answer
Answer: B
The domain name sits between https:// and the next /. It names the server; the rest says which page.
3. The packets of one photo arrive out of order. What happens?
Show the answer
Answer: B
Packets are numbered for exactly this reason. Only missing packets are asked for again.
Key points
- Devices find each other by IP address; DNS turns names like
example.cominto those addresses. - Data travels in numbered packets that are put back together at the end.
- Your browser asks, a server answers. HTTPS keeps the conversation private, but still check the domain name.
Practice
3 short exercises: think it through, change something and see what happens, then do one yourself. Answers are checked the moment you submit.
- ThinkWhere would you log in?
Your bank's website is
examplebank.com. You need to type your password. Which address is safe? - ChangeTeach the phone book a new name
The machine is asked for
news.org, but its phone book doesn't know that name yet, so it printsServer not found.Add a line to the phone book so that
news.orgis at198.51.100.99, and the machine prints:news.org is at 198.51.100.99Keep looking up
news.org. - Your turnThe journey of a page
Put the steps of opening
https://example.comin order:- A The server sends the page back in packets.
- B DNS turns
example.cominto an IP address. - C You type the address and press Enter.
- D Your browser sends a request to that IP address.
- E Your browser puts the packets together and shows the page.
Write the five letters in order, for example
ABCDE.
Practise this lesson
Open the interactive lesson to edit and run these examples and solve the exercises with instant feedback. Free to start, no sign-up.
Interactive lessons open in order. If you have not done the earlier ones yet, you start at the course map.
Terms in this lesson
| Term | Chinese | Definition |
|---|---|---|
| Internet | 互联网 | A worldwide network of networks that lets computers exchange data. |
| IP address | IP 地址 | A number that identifies a device on a network, like a street address. |
| DNS | 域名系统 | The system that turns domain names into IP addresses, like a phone book. |
| Packet | 数据包 | A small numbered piece of data sent across a network. |
| Server | 服务器 | A computer that is always on and answers requests from other computers. |
| URL | 网址 | A web address: protocol, domain name and path, such as https://example.com/news. |
| HTTPS | HTTPS 加密连接 | HTTP with encryption, so nobody in between can read or change the data. |