How the Internet Works: Networks, Packets and Protocols
When you open a video on your phone, the data cross dozens of devices owned by different companies, cut into small pieces that can each take their own route. It works because every one of those devices follows the same published rules. Here is how the pieces fit together, from your phone to a server and back.
What is a computer network?
A computing device is a physical object that can run a program. Phones, laptops, game consoles, servers, routers and smart thermostats are all computing devices.
A computing system is a group of computing devices and programs working together for a common purpose. Your school's online gradebook is one: teachers' laptops, the server that stores the grades, and the app on your phone all work together so you can see your scores.
A computer network is a group of interconnected computing devices that can send or receive data. A network is a type of computing system. The devices in your home that share one Wi-Fi router form a small network.
What is a path, and what is routing?
When one device (the sender) sends data to another (the receiver), the data rarely go straight there. They hop from device to device. A path is a sequence of directly connected devices that starts at the sender and ends at the receiver. Routing is the process of finding a path.
Below, a small network is stored as a dictionary: each device maps to the list of devices it is directly connected to. An ISP (Internet service provider) is the company that connects your home to the rest of the Internet.
phone is directly connected to home router home router is directly connected to phone, laptop, ISP router laptop is directly connected to home router ISP router is directly connected to home router, router B, router C router B is directly connected to ISP router, router D router C is directly connected to ISP router, router D router D is directly connected to router B, router C, video server video server is directly connected to router D 5 hops: phone -> home router -> ISP router -> router B -> router D -> video server 5 hops: phone -> home router -> ISP router -> router C -> router D -> video server
There are two paths from the phone to the video server, one through router B and one through router C. On the Internet, routing is usually dynamic: the path is not decided in advance. Each router picks the next hop based on conditions at that moment, such as which links are busy or broken, so two packets from the same video can travel different paths.
No single device holds a map of the whole Internet. A router knows its own neighbours and which of them leads toward each group of addresses, and routers keep telling each other about changes. Every hop moves the data a little closer, and together the hops form the path.
Write is_path(network, route). network is a dictionary that maps each device to the list of devices it is directly connected to, and route is a list of devices. Return True if route is a path: it has at least two devices (a sender and a receiver), and every device in it is directly connected to the next one. Otherwise return False.
net = {'A': ['B', 'C'], 'B': ['A', 'D'], 'C': ['A', 'D'], 'D': ['B', 'C', 'E'], 'E': ['D']}
is_path(net, ['A', 'B', 'D', 'E']) -> True
is_path(net, ['A', 'D', 'E']) -> False (A and D are not directly connected)What is bandwidth?
The bandwidth of a network is the maximum amount of data that can be sent in a fixed amount of time. It is usually measured in bits per second, most often in megabits per second (Mbps, millions of bits per second). Bandwidth works like the number of lanes on a highway: more lanes let more cars through each minute.
File sizes are usually given in bytes, and a byte is 8 bits, so to find a download time you first multiply by 8. Bandwidth is a maximum, so real downloads are often slower, for example when the whole family is streaming at once.
file 10 Mbps 100 Mbps 1000 Mbps song 3.2 s 0.32 s 0.03 s phone photo 2.4 s 0.24 s 0.02 s TV episode 12.0 min 1.2 min 7.2 s game update 66.7 min 6.7 min 40.0 s
Write transfer_seconds(megabytes, mbps). It returns the least time, in seconds, to send a file of megabytes megabytes over a connection with a bandwidth of mbps megabits per second, rounded to 1 decimal place.
transfer_seconds(100, 50) -> 16.0 (100 MB is 800 megabits, and 800 / 50 = 16)What makes the Internet different from other networks?
The Internet is a network made of many interconnected networks, such as home networks, school networks, phone carriers and huge company networks, all using standardized, open (nonproprietary) communication protocols.
A protocol is an agreed-upon set of rules that specify how a system behaves. Think of addressing an envelope: because everyone agrees where the address and stamp go, any post office in the world can handle your letter. Internet protocols say things like how an address is written, how big a piece of data can be, and what a device does when something goes wrong.
The Internet's protocols are open: they are published for anyone to read and use, and no company owns them. That makes it easy to connect new devices. A start-up that invents a new smart doorbell does not need permission from anyone; it builds the doorbell to follow the protocols, and it works.
Getting on the Internet depends on connecting your device to a device that is already connected, such as a Wi-Fi router, a cell tower or a school's network switch.
The scalability of a system is its capacity to change in size and scale to meet new demands. The Internet was designed to be scalable. The network that grew into it connected four computers in 1969; today the Internet connects billions of devices, and adding another network does not require redesigning the ones already there.
How does data travel in packets?
Information moves through the Internet as a data stream. The stream is cut into chunks, and each chunk is wrapped, or encapsulated, in a packet. A packet holds its chunk of data plus metadata: information used to route it from the origin to the destination (such as both addresses) and to put the data back together (such as the packet's number in the sequence).
A packet usually carries at most about 1,500 bytes of data, so one phone photo becomes about two thousand packets.
Why cut data up at all? Small packets let many people share the same links at once, the way many cars share a road, instead of one huge file blocking a link until it finishes. If a link fails or a packet is lost, only that small piece has to be sent again, and later packets can take another route around the problem.
Packets travel independently, so they may arrive in order, out of order, or not at all. The demo cuts a message into packets, then shuffles them and loses one, the way a real network sometimes does.
7 packets. The first one:
{'from': '192.0.2.15', 'to': '198.51.100.7', 'seq': 1, 'total': 7, 'data': 'Meet at '}
Arrival order: [6, 5, 7, 4, 1, 3]The receiver uses the metadata to rebuild the message. Sorting by sequence number fixes the order, and a gap in the numbers shows which packet never came.
Missing packets: [2] Rebuilt so far: Meet at [?]ary at 3:30 and bring your laptop! After resending: Meet at the library at 3:30 and bring your laptop!
Write reassemble(packets, total). packets is a list of dictionaries with the keys "seq" (1 to total) and "data", in the order they arrived. Return the full message with the chunks in sequence order. If any packet from 1 to total is missing, return None. The same packet can arrive twice; use it once.
reassemble([{'seq': 2, 'data': 'lo!'}, {'seq': 1, 'data': 'Hel'}], 2) -> 'Hello!'What do IP, TCP and UDP do?
IP, TCP and UDP are common protocols on the Internet. They usually work in layers, each handling one part of the job.
192.0.2.15, and IP gets each packet from router to router toward the address on it.Is the World Wide Web the same as the Internet?
No. The World Wide Web is a system of linked pages, programs and files: everything you reach through links in a browser. HTTP (and its secure version, HTTPS) is the protocol the web uses: your browser sends an HTTP request asking for a page, and the server sends an HTTP response back.
The web uses the Internet to move those requests and responses. HTTP messages are cut into packets and carried across the Internet's protocols, usually TCP and IP, like any other data. Plenty of what travels on the Internet is not the web at all, such as the email app on your phone, video calls and multiplayer games.
A web address shows the layers. The program below splits one into its parts.
Protocol: https Server: pythoncompiler.io Page: /python/exercises/ The browser's request starts like this: GET /python/exercises/ HTTP/1.1 Host: pythoncompiler.io
Check your understanding
A small company invents a new kind of smart speaker. It connects to the Internet without the company asking any other organization for permission. Which of the following best explains why this is possible?
Which of the following are typically included in a packet's metadata? Select two answers.
Select 2 answers.
Which of the following best describes the relationship between the Internet and the World Wide Web?
A network has a bandwidth of 50 megabits per second. What is the least amount of time it can take to send a 200-megabit file over this network?
In a network, these pairs of devices are directly connected: A and B, A and C, B and D, C and D, D and E. Which of the following is a path from A to E?
You load the same website twice, a minute apart, and the packets travel through different routers each time. Which of the following best explains this?
The Internet was designed to be scalable. What does this mean?
Exam topics: 4.1 The Internet (CSN-1.A, CSN-1.B, CSN-1.C, CSN-1.D)