1 / 6 · Basic
What the internet is
Wiring 10 computers directly to each other takes 45 cables. The internet gets around that with switches and routers.
Jump to the 10 practice questionsYou will learn
- Explain why switches and routers beat a cable for every pair
- Describe packet switching
1Explain
A photo from the subway
Say you are on the subway and send a photo to a friend who is at home. (This is a made-up example.) Your phone passes the photo to the mobile network. Your friend's phone picks it up from the Wi-Fi router in the living room. In between, the photo crosses machines that belong to several different companies, and nobody worked out that exact route in advance. It arrives anyway. To see how, start with a much smaller network.
2Explore
Ten computers, forty-five cables
Two computers can talk over one cable or one wireless link. Now try ten, and give every computer its own cable to every other one. MDN's guide to how the internet works counts the cost: 45 cables, with nine plugs on each computer. The sum is 10 × 9 ÷ 2. Each machine needs a line to the nine others, and you halve the total because every cable has two ends. With 20 computers the same sum gives 190. The count grows roughly with the square of the number of machines, so nobody builds a network this way.
The first line is the cables for a cable between every pair, the second the cables with one switch in the middle.
const n = 10;
console.log(n * (n - 1) / 2);
console.log(n);45
103Problem
Ten computers
How many cables does it take to join 10 computers so that every pair has its own cable?
cables
Hint
10 × 9 ÷ 2.
Solution
Answer: 45 cables
10 × 9 ÷ 2 = 45. Each computer needs 9 links and every cable has two ends.
4Problem
Twenty computers
And for 20 computers?
cables
Hint
20 × 19 ÷ 2.
Solution
Answer: 190 cables
20 × 19 ÷ 2 = 190. The count grows roughly with the square of the number of computers.
5Explain
One switch in the middle
The usual fix is a small computer called a switch. Each machine gets one cable to the switch, so ten computers need ten cables, and the switch passes every message to the right machine. The switch tells machines apart by their MAC addresses. A MAC address identifies a network interface on a local network. Devices may use private MAC addresses that change between networks or over time. Inside one building that works well. A switch that had to remember every device on Earth would not.
6Problem
Cables with a switch
With one switch in the middle, how many cables do 10 computers need?
cables
Hint
One cable from each computer to the switch.
Solution
Answer: 10 cables
One cable from each computer to the switch: 10.
7Explain
The box at home links your network to everyone else's
Between networks the job goes to routers. A router reads a different kind of address, the IP address, which works more like a street address: it says which network a device belongs to. That lets a router keep one rule for a whole group of addresses instead of one rule per device. The router in your home links your home network to an internet service provider (ISP), and ISPs link their routers to each other's. The internet is that whole mesh of joined networks.
8Problem
What a router joins
What does a router join together?
Hint
It reads IP addresses, which name networks.
Solution
Answer: Separate networks
Routers pass packets between networks using IP addresses. Switches handle the machines inside one local network.
9Explore
A photo leaves in pieces
An old telephone call held one complete line between two phones for as long as the call lasted, silences included. The internet does something else. Data is cut into small pieces called packets, and each packet carries the address it is going to. Packets from millions of people take turns on the same cables. If one goes missing, only that piece has to be sent again. If a route breaks, the rest can go another way. The name for this is packet switching.
Drag to turn. Scroll or pinch to zoom.
10Explain
Overtaking and cut links
Watch the packet numbers as they land. Packets on the faster lower route can overtake the ones on the upper route. Now use the menu to cut a link and send again: the routers steer everything around the gap. Cut the link between R5 and the server, though, and nothing gets through. The server has only that one connection.
11Problem
Packet switching
What is packet switching?
Hint
Pieces with addresses, sharing the cables.
Solution
Answer: Cutting data into addressed pieces that share the links
Reserving a whole line is circuit switching, how old telephone calls worked.
12Problem
Why packets help
Why is it useful to cut a big file into packets?
Hint
Think of one lost piece and one broken link.
Solution
Answer: A lost piece can be resent alone, and packets can go around a broken link
Cutting does not compress or hide the data, and packets can be lost. The gain is sharing and recovery.
13Problem
Back in order
In the simulator the packets reached the server out of order. How does the server rebuild the message?
Hint
Each packet carries a number.
Solution
Answer: By the sequence number in each packet
TCP numbers the bytes it sends, so the receiver can put them back in order.
14Explain
The internet is not the web
One more distinction before the history. The internet and the web are not the same thing. The internet is the set of connected networks. The web is one service that runs on top of it, where web servers send pages to web browsers. Email, video calls and online games are other services on the same networks. A chat app or a game can use the internet all day without opening a single web page.
15Problem
The internet and the web
Which sentence is true?
Hint
One is the networks, the other a service on them.
Solution
Answer: The web is a service that runs on the internet
The internet is the connected networks. The web, email and games are services using them.
16Explain
"LO"
On 29 October 1969 at 22:30, Charley Kline, a student working with Professor Leonard Kleinrock at UCLA, tried to log in to a computer at the Stanford Research Institute over the new ARPANET. He meant to type "login". The letters L and O went through, and then the system crashed. So the first message on the network that grew into the internet was "LO". About an hour later the full login worked. On 1 January 1983 the ARPANET switched to the TCP/IP protocols that the internet still uses.
17Problem
The first message
Hint
The system crashed after two letters of "login".
Solution
Answer: LO
Kline typed "login"; the system crashed after L and O.
18Problem
The switch to TCP/IP
In which year did the ARPANET switch to TCP/IP?
Hint
1 January, fourteen years after the first message.
Solution
Answer: 1983
The switch-over date was 1 January 1983.
19Practice
Put the packets back in order
The four packets arrived out of order. Sort them by their sequence number and join their data, so the program prints the original message.
Hello!const arrived = [
{ seq: 3, data: "lo" },
{ seq: 1, data: "He" },
{ seq: 4, data: "!" },
{ seq: 2, data: "l" },
];
let message = "";
for (const p of arrived) message += p.data;
console.log(message);
Hint
sort with (a, b) => a.seq - b.seq puts the smallest number first.
A solution
const arrived = [
{ seq: 3, data: "lo" },
{ seq: 1, data: "He" },
{ seq: 4, data: "!" },
{ seq: 2, data: "l" },
];
arrived.sort((a, b) => a.seq - b.seq);
let message = "";
for (const p of arrived) message += p.data;
console.log(message);20Explain
Common mistakes
"The internet and the web are the same thing."
The internet is the connected networks. The web is one service on top of them, where servers send pages to browsers. Email, video calls and games use the same networks and are not part of the web.
"When I send a photo, my phone opens a line straight to my friend's phone."
That is how old telephone calls worked, and it is called circuit switching. The internet cuts the photo into packets, and each packet finds its own way while sharing the cables with everyone else's packets.
"Full Wi-Fi bars mean the internet is working."
Wi-Fi is only the short wireless hop between your device and the router. Full bars say that hop is fine. If the router's link to the ISP is down, pages still will not load.
21
Summary
- The internet is many networks joined by routers.
- Switches connect machines in one local network by MAC address; routers forward between networks by IP address.
- Data travels as packets that share links and can take different routes.
- The web, email and games are services that run on the internet.