Everyone Can Learn Program
中文 Start learning
Course 0 · Before codeLesson 6 of 8Free to read

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 contents

Why 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.

  1. 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.
  2. 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.
  3. 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.
  4. 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 yourself

This 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)
Step by step
  1. L2The phone book: each name with its IP address.example.com → 203.0.113.7
  2. L6The name to look up.name = "school.edu"
  3. L7Is the name in the book?yes
  4. L8Answer with its address.school.edu is at 198.51.100.20

Cut into packets

Try it yourself

A 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
Step by step
  1. L1The message to send.message = "See you at six"
  2. L2Each packet carries 4 characters.size = 4
  3. L5Packet 1 gets the first four characters, space included.packet 1 [See ]
  4. L5The last packet holds what's left.packet 4 [ix]

Back in order

Try it yourself

The 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)
Step by step
  1. L1Packets in the order they arrived: (number, piece).3, 1, 4, 2
  2. L2Sort them by number.1, 2, 3, 4
  3. L5Join the pieces.message = "See you at six"
  4. 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?

  1. ATurns domain names into IP addresses
  2. BMakes pages load faster by shrinking them
  3. CStores your passwords
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?

  1. Ahttps://
  2. Bwww.example.com
  3. C/news/today.html
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?

  1. AThe photo is broken for good
  2. BYour computer puts them back in order by their numbers
  3. CThe server has to send the whole photo again in one piece
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.com into 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.

  1. ThinkWhere would you log in?

    Your bank's website is examplebank.com. You need to type your password. Which address is safe?

  2. 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 prints Server not found.

    Add a line to the phone book so that news.org is at 198.51.100.99, and the machine prints:

    news.org is at 198.51.100.99

    Keep looking up news.org.

  3. Your turnThe journey of a page

    Put the steps of opening https://example.com in order:

    • A The server sends the page back in packets.
    • B DNS turns example.com into 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

TermChineseDefinition
Internet互联网A worldwide network of networks that lets computers exchange data.
IP addressIP 地址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.
HTTPSHTTPS 加密连接HTTP with encryption, so nobody in between can read or change the data.