An Animated Lesson
Key points of this lesson
- The internet is a network of networks, joined by routers that pass data along one hop at a time.
- Data travels in small numbered packets that can take different routes and arrive in any order.
- TCP puts packets back in order and asks again for any that go missing, which makes an unreliable network reliable.
- Routers find fast paths using shortest path algorithms, and traffic flows around broken links automatically.
- DNS turns names like school.example into IP addresses, and caching makes repeat lookups almost instant.
- HTTPS encrypts traffic with keys so large that guessing them is impossible, unlike the Caesar cipher students crack here.
Who this lesson is for and how to use it
This is the third lesson in our Computer Science Education series. In How a Computer Works students learned that everything inside a machine is binary. In How AI Learns they saw that clever behaviour can come from very simple steps repeated many times. This lesson takes both ideas outside the box. What happens when billions of computers need to talk to each other?
The material suits grades nine to twelve and first year college students. No programming is needed for the labs, and the Python code at the end rebuilds each one for students who want to go further. Every animation and lab runs in the browser on a projector or a phone, so pairs of students can take turns at the controls.
Learning objectives
After three periods, a student should be able to do the following five things without notes.
- Explain why data is split into packets and what the sequence number on each packet is for.
- Describe what TCP does when packets arrive out of order or go missing.
- Explain how routers forward packets and why the internet keeps working when one link fails.
- Walk through a DNS lookup from a laptop to an authoritative server, and explain the role of the cache.
- Explain why the Caesar cipher is weak and what makes HTTPS encryption strong.
| Period | Focus | Activity on this page | Time |
|---|---|---|---|
| 1 | Networks, packets and TCP | Animated packet journey, Lab 1 packet sender, the paper packet game | 40 minutes |
| 2 | Routers, routing and IP addresses | Lab 2 routing with cable cuts, layer diagram, binary IP addresses | 40 minutes |
| 3 | DNS, the web, encryption and safety | Lab 3 DNS lookup, Lab 4 cipher cracker, quiz, Python demo | 40 minutes |
What the internet actually is
Start with a correction that changes how students see everything else. The internet is not a place and it is not one big computer. It is a network of networks. Your school has a network. Your home has one. Mobile phone companies, universities, banks and video sites each run their own. The internet is the agreement that lets all of them pass data to each other, plus the cables and machines that carry it.
Most of that carrying happens through physical cables. Fibre optic lines run under city streets, along railway tracks and across the ocean floor, and the great majority of traffic between continents travels through undersea cables rather than satellites. Light in glass fibre moves at roughly two thirds of its speed in a vacuum, around 200,000 kilometres every second, which is why a message can cross the planet and come back in well under a second. Wireless networks only carry the first or last few metres, from your phone to the nearest router.
A router is the key machine. Its job is simple to describe. A piece of data arrives, the router reads where it is going, and it sends it one step closer. It does not need to know the whole route. It only needs to know which neighbour is a good next step, much like a person giving directions who says turn left at the mosque and ask again at the market.
Packets, why messages get chopped up
Old telephone networks worked by circuit switching. When you made a call, the exchange connected a dedicated wire path from your phone to the other phone, and that path belonged to you until you hung up. It worked, but it wasted capacity, since the line sat reserved even during silences, and a single broken switch along the way ended the call.
In the early 1960s Paul Baran at the RAND Corporation in the United States proposed a different design, a mesh network with no central point where messages were broken into small blocks that could each find their own route. A few years later Donald Davies at the National Physical Laboratory in Britain arrived at the same idea independently and gave the blocks the name we still use. He called them packets.
Packet switching has three big advantages that students can discover for themselves in the lab below. Many conversations can share the same cables, because packets from different users interleave like cars from different side streets merging onto one road. A damaged route only affects the packets that were on it. And if one packet is lost, only that small piece needs sending again, not the whole file.
Send your own packets
Type a short message and press Send. The lab cuts it into numbered packets and launches them across the network. Watch them arrive in a scrambled order and then fall into place by their numbers. Now tick Lossy network and send again. Some packets will disappear on the way, the receiver will notice the gaps, and the Ask again button will request only the missing pieces. That is exactly what TCP does on every device students own.
Receiver slots, sorted by sequence number
Press Send to launch the packets.
Every packet carries more than its slice of the message. It has a header, a small label at the front that holds the sender’s address, the destination address and the sequence number. Routers only ever read the header, the way a postal worker reads the envelope and never opens the letter. Real packets usually hold up to about fifteen hundred bytes, so a single photo might travel as hundreds of them.
Teacher note, the paper packet game
Write a ten word sentence on ten numbered slips of paper, one word each. Hand the slips to students around the room and ask them to pass each slip toward a receiver at the front, but only to a neighbour. Secretly tell one student to keep a slip in their pocket. The receiver sorts the slips, spots the missing number and calls out for it again. In five minutes the class has acted out packet switching, routing and TCP without touching a computer.
Key takeaway
The network itself is allowed to be messy. Packets can arrive late, out of order or not at all. Reliability comes from the computers at each end, which number every packet, check for gaps and ask again.
Layers, the internet as a stack of envelopes
No single program handles everything a message needs. Engineers split the job into layers, each doing one task and trusting the layer below it to do the rest. The model taught in most schools is the four layer TCP/IP model, named after its two most famous protocols. A protocol is simply an agreed set of rules for how two machines talk, the way a phone call has an unspoken rule that both people do not speak at once.
Think of each layer as an envelope. Your message is written by an application such as a browser. The transport layer puts it in an envelope marked with sequence numbers. The internet layer puts that into a bigger envelope with the destination IP address. The link layer wraps it once more for the local hop over WiFi or a cable. At the other end the envelopes are opened in reverse order, and the browser on the server reads exactly what the browser on your laptop wrote.
The design came from Vint Cerf and Bob Kahn, who described it in a 1974 paper titled A Protocol for Packet Network Intercommunication. Its strength is that each layer can change without breaking the others. The link layer has moved from telephone lines to fibre and wireless over fifty years, and web browsers never needed to notice. On 1 January 1983 the ARPANET, the research network that grew into the internet, switched over to TCP/IP completely, and many engineers treat that date as the real birthday of the internet.
IP addresses, every device needs a number
A packet cannot be delivered without an address, and on the internet that address is an IP address. The common version, IPv4, writes it as four numbers separated by dots, such as 192.0.2.10. Students who did our first lesson will recognize what each of those numbers really is. Every part runs from 0 to 255, because each is one byte of eight bits, and the whole address is just 32 bits.
Just over four billion addresses sounded endless in the 1980s. It is not enough for a world where every person may carry a phone, a watch and a laptop. Engineers responded in two ways. Home routers use a trick called network address translation, which lets every device in a house share one public address. And a newer version, IPv6, was standardized in 1998 with 128 bit addresses, enough to give a separate address to every grain of sand on Earth many times over. Both versions run side by side on today’s internet.
Routing, how packets find their way
When a packet reaches a router, the router checks its forwarding table, a list that says which neighbour to use for each range of destination addresses. Inside a single large network, such as a university or an internet provider, routers build those tables by sharing information about which links exist and how fast they are. Each router then runs a shortest path algorithm to choose the best next step for every destination.
The classic method was invented by the Dutch computer scientist Edsger Dijkstra, who later said he worked it out in about twenty minutes while sitting at a café in Amsterdam, and published it in 1959. The idea is easy to follow. Start at your own router with a cost of zero. Always look next at the closest router you have not finished with, and update the cost of reaching each of its neighbours if going through it is cheaper. When you reach the destination, you have the fastest path.
In the lab below each cable shows its delay in milliseconds. Press Find fastest route and watch routers light up in the order Dijkstra visits them, then follow the orange packet along the winning path. Now click any cable on that path to cut it, as if a digger had sliced through it, and find the route again. Students quickly see the most important property of the internet, that there is almost always another way.
Press Find fastest route.
With every cable working the fastest route takes 25 milliseconds, going the long way round through C, E and D rather than straight through B. Cut the cable between E and D and the best route becomes 29 milliseconds through B. Cut enough cables and the server becomes unreachable, which is what happens when a whole region loses connectivity. Between the separate networks that make up the internet, a different protocol called BGP does the same job at a larger scale, choosing routes by agreements between companies as well as by speed.
No router knows the whole internet. Each one only knows a good next step, and somehow billions of packets still arrive.From this lesson, period two
DNS, the phone book of the internet
People remember names and computers need numbers. The Domain Name System connects the two. It was designed by Paul Mockapetris in 1983, when the old method, a single text file of every computer name that administrators downloaded from one central place, could no longer keep up with the growing network. The full design is still described in the documents RFC 1034 and 1035 from 1987.
DNS is a tree. At the top are the root servers, organized as thirteen named systems that are each copied to many locations around the world. Below them are servers for each top level domain, such as .com, .org or .pk. Below those, every organization runs servers that know the addresses of its own names. No single machine holds the whole phone book, so the system never runs out of room and never has one point that can bring it all down.
In the lab, choose a name and press Look up. The example names and addresses come from ranges reserved for teaching and documentation, so they will never clash with a real website. Watch the question travel from your laptop to a resolver, up to the root, down to the .example servers, and finally to the server that holds the answer. Then look up the same name again.
Choose a name and press Look up.
The second lookup is instant because the resolver kept the answer in its cache. Real DNS answers come with a time to live, a number of seconds the answer may be reused before asking again. Caching is why DNS can serve billions of lookups every day without the root servers collapsing under the load. It is also the reason a website that changes its address can take a while to appear in its new home for everyone.
For a clear second explanation with diagrams, the Cloudflare Learning Center guide to DNS is written for beginners and works well as homework reading.
The web is not the internet
Students use the two words as if they mean the same thing, and correcting that is worth five minutes. The internet is the network, the cables, routers and protocols that move packets. The World Wide Web is one service that runs on top of it, a system of pages linked to each other and fetched by browsers. Email, online games, video calls and app notifications also travel over the internet without being part of the web.
The web was proposed in 1989 by Tim Berners-Lee, a British scientist working at CERN, the physics laboratory near Geneva, as a way for researchers to share documents. His three ideas still run every website. URLs give each page an address, HTTP is the protocol a browser uses to ask for a page, and HTML is the language the page is written in. When a student types a web address, their browser first uses DNS to find the server’s IP address, then opens a TCP connection to it, then sends an HTTP request through that connection. Every lab on this page is one step in that chain.
Encryption, why the padlock matters
Here is something that surprises students. Every packet passes through many routers owned by many different organizations, and in principle any of them could read the header and the contents. On a public WiFi network in a café, other people nearby can sometimes capture packets too. So how can anyone safely type a password or a bank card number into a website?
The answer is encryption. Before a packet leaves the browser, its contents are scrambled with a key that only the browser and the server know. Routers can still read the outer envelope to deliver it, but the letter inside is unreadable. That is what HTTPS means, and the padlock in the address bar says the connection is encrypted. To feel why the size of the key matters so much, try the oldest cipher in history, the one Julius Caesar reportedly used to send military orders, shifting every letter a fixed number of places along the alphabet.
What an eavesdropper on the network sees
Change the key, then play the attacker.
The cipher falls in under two seconds because there are only 26 possible keys, and a computer can try them all before a student finishes blinking. Modern encryption follows the same basic idea, a key that scrambles and unscrambles, but uses keys of 128 or 256 bits. A 256 bit key has more possible values than there are atoms on planet Earth, so trying them all is not slow, it is physically impossible. HTTPS also solves a harder puzzle, how two computers that have never met can agree on a secret key over a network anyone can listen to, using a clever branch of mathematics called public key cryptography. Students heading toward security careers can follow that thread in our cybersecurity section.
Key takeaway
Encryption does not hide that you are communicating, and it does not make a dishonest website honest. It makes sure that what you send can only be read by the computer you sent it to. Look for HTTPS before typing anything private.
Teacher note, staying safe online
Close period three with a short discussion that turns the theory into habits. Why should you avoid logging into a bank on unknown public WiFi? Why can a phishing site still show a padlock? What does a strange looking web address tell you? Students who understand packets, DNS and encryption reason through these questions far better than students who only memorize rules.
Misconceptions students bring to class
- The internet and the web are the same thing. The web is one service that runs on the internet, alongside email, games and video calls.
- The internet is mostly satellites. Almost all long distance traffic travels through cables on land and under the sea.
- WiFi is the internet. WiFi only connects a device to a nearby router. Everything beyond that router is wired.
- A message travels as one piece along one path. It travels as many packets, which may take different paths and arrive in any order.
- Incognito mode makes you invisible. It only stops the browser saving your history on that device. The network can still see where packets go.
Where this lesson simplifies the truth
Every lab here is a teaching model. Real TCP does not wait for a whole message before asking for missing packets. The receiver constantly sends acknowledgements, and the sender resends anything that has not been acknowledged after a timeout, while also slowing down when the network seems crowded. Real routers do not recalculate a full route for every packet. They look up the destination in a forwarding table that is updated in the background whenever links change.
The DNS lab skips several details too. Resolvers usually already have the root and top level answers cached, so a real lookup rarely visits every server. And the cipher lab uses a cipher no real system has trusted for centuries. Modern encryption relies on mathematics well beyond a school course, though the core idea, that security depends on the number of possible keys, carries over exactly.
None of this changes the main picture. A student who can explain the four labs on this page understands the ideas that every network engineer builds on.
Bringing it all together
The main achievement of this lesson is a complete story of what happens after a single tap. The browser asks DNS to turn a name into an IP address. It opens a TCP connection and encrypts everything with HTTPS. Its request is cut into numbered packets, wrapped in layer after layer of headers, and handed to the network. Routers pass each packet along the fastest path they know, flowing around any broken links, and at the far end TCP sorts the packets back into order and asks again for anything lost. The reply makes the same trip in reverse, often in less time than it takes to blink.
The conceptual shift is from seeing the internet as a magical cloud to seeing it as a very large, very patient delivery system built from simple parts. No part of it is especially clever on its own. Its strength comes from the design choices students met today, packets instead of fixed circuits, no central controller, layers that can change independently, and reliability added at the edges rather than demanded from the middle.
Those ideas reach well beyond networking. Shortest path algorithms power map apps and delivery planning. Caching makes everything from phones to processors faster, the same principle as the memory pyramid in our first lesson. Layering is how almost all large software is organized. And the encryption story leads directly to cybersecurity, one of the fastest growing career paths for computer science students.
There are honest limits here. The lesson leaves out wireless physics, congestion control, the business agreements behind routing between companies, and the mathematics of public key cryptography. Teachers with stronger classes can extend period two by having students run Dijkstra by hand on a printed map of their own city, and teachers without computers can rely on the paper packet game and a pencil and paper version of the cipher.
A natural next lesson is cybersecurity itself, covering passwords, phishing and how attackers misuse the very protocols students learned today. For now, the class that started by saying it is just the WiFi can explain a journey that crosses oceans in a fraction of a second, one packet at a time.
Companion Python code for the classroom
The program below rebuilds every lab in plain Python with no extra libraries. It splits a message into packets, loses some at random and recovers them the way TCP does, runs Dijkstra’s algorithm on the same network as Lab 2 before and after a cable cut, performs a cached DNS lookup and prints an IP address in binary, and encrypts and decrypts with a Caesar cipher. It runs in any Python 3 setup, including free online editors.
# How the Internet Works, companion code for the aitrendblend lesson # Runs on any Python 3 installation. No extra libraries needed. import heapq import random random.seed(3) # Part 1. Packets, splitting a message and putting it back together def split_into_packets(message, size=5): """Cut a message into numbered packets, like TCP segments.""" return [(seq, message[i:i + size]) for seq, i in enumerate(range(0, len(message), size))] def send_over_network(packets, loss_rate=0.2): """Packets arrive in a random order and some go missing.""" arrived = [p for p in packets if random.random() > loss_rate] random.shuffle(arrived) return arrived def reassemble(packets, total): """Sort by sequence number and report any gaps.""" got = dict(packets) missing = [seq for seq in range(total) if seq not in got] return missing, "".join(got[s] for s in sorted(got)) def reliable_transfer(message, size=5, loss_rate=0.2): """Keep asking for missing packets until nothing is missing, like TCP.""" packets = split_into_packets(message, size) received, rounds = {}, 0 while len(received) < len(packets): rounds += 1 wanted = [p for p in packets if p[0] not in received] for seq, data in send_over_network(wanted, loss_rate): received[seq] = data return "".join(received[s] for s in sorted(received)), rounds # Part 2. Routing, finding the fastest path with Dijkstra's algorithm LINKS = { # delay in milliseconds between routers ("Home", "A"): 5, ("A", "B"): 12, ("A", "C"): 7, ("B", "D"): 9, ("C", "D"): 15, ("C", "E"): 6, ("E", "D"): 4, ("D", "Server"): 3, ("B", "Server"): 20, } def build_graph(links, broken=()): graph = {} for (a, b), cost in links.items(): if (a, b) in broken or (b, a) in broken: continue graph.setdefault(a, []).append((b, cost)) graph.setdefault(b, []).append((a, cost)) return graph def shortest_path(graph, start, goal): queue, seen = [(0, start, [start])], set() while queue: cost, node, path = heapq.heappop(queue) # always expand the cheapest so far if node == goal: return cost, path if node in seen: continue seen.add(node) for nxt, step in graph.get(node, []): if nxt not in seen: heapq.heappush(queue, (cost + step, nxt, path + [nxt])) return None, [] # Part 3. DNS, turning names into numbers with a cache ZONE = {"school.example": "192.0.2.10", "library.example": "198.51.100.7", "news.example": "203.0.113.42"} cache = {} def dns_lookup(name): if name in cache: return cache[name], "from cache" steps = ["root server", "." + name.split(".")[-1] + " server", name + " server"] ip = ZONE.get(name) if ip: cache[name] = ip return ip, " -> ".join(steps) def ip_to_binary(ip): """Every IPv4 address is just 32 bits, written as four bytes.""" return ".".join(format(int(part), "08b") for part in ip.split(".")) # Part 4. Encryption, a Caesar cipher (fine for class, never for real secrets) def caesar(text, shift): out = [] for ch in text: if ch.isalpha(): base = ord("A") if ch.isupper() else ord("a") out.append(chr((ord(ch) - base + shift) % 26 + base)) else: out.append(ch) return "".join(out) # Smoke test if __name__ == "__main__": msg = "MEET AT THE LIBRARY AT FIVE" pk = split_into_packets(msg) print("Packets:", pk) missing, partial = reassemble(send_over_network(pk), len(pk)) print("One unreliable send, missing packets", missing, "->", repr(partial)) text, rounds = reliable_transfer(msg) print(f"Reliable transfer rebuilt {text!r} in {rounds} rounds") g = build_graph(LINKS) print("Fastest route:", shortest_path(g, "Home", "Server")) g2 = build_graph(LINKS, broken=[("E", "D")]) print("After the E to D cable is cut:", shortest_path(g2, "Home", "Server")) print("First lookup:", dns_lookup("school.example")) print("Second lookup:", dns_lookup("school.example")) print("192.0.2.10 in binary:", ip_to_binary("192.0.2.10")) secret = caesar("Hello class", 3) print("Encrypted:", secret, "| Decrypted:", caesar(secret, -3)) assert text == msg assert shortest_path(g, "Home", "Server") == (25, ["Home", "A", "C", "E", "D", "Server"]) assert shortest_path(g2, "Home", "Server")[0] == 29 assert caesar(caesar("Zebra", 5), -5) == "Zebra" print("\nAll checks passed.")
When you run it, the reliable transfer should rebuild the full message, the fastest route should cost 25 milliseconds and rise to 29 after the cut, the second DNS lookup should come from the cache, and the final line should report that all checks passed. A good extension task is to write a function that cracks the Caesar cipher automatically by trying every key and counting common English words, exactly like Lab 4.
Check your understanding
Six questions cover the whole lesson. Choose an answer for each and press Check answers to see which were right, with a short explanation for each.
Frequently asked questions
How does the internet work, explained simply?
Data is split into small numbered packets. Routers pass each packet one step closer to its destination, and the receiving computer puts the packets back in order and asks again for any that were lost. DNS turns names into addresses so packets know where to go.
What is a packet in networking?
A packet is a small piece of data with a header that holds the sender address, the destination address and a sequence number. Messages, photos and videos all travel across the internet as many packets.
What does TCP do?
TCP makes an unreliable network reliable. It numbers every packet, puts them back in order at the receiver, and resends any that go missing, so the full message always arrives intact.
What is DNS and why is it needed?
DNS, the Domain Name System, translates names people remember, like school.example, into the IP addresses computers use. It is spread across many servers in a tree, and caching makes repeat lookups almost instant.
Is the internet the same as the World Wide Web?
No. The internet is the global network that moves packets. The web is one service that runs on it, made of linked pages fetched by browsers using HTTP. Email and video calls use the internet without being part of the web.
Can this lesson be taught without computers?
Yes. The paper packet game uses numbered slips passed around the room, Dijkstra can be run by hand on a printed map, and the Caesar cipher works with pencil and paper.
Take the lesson further
Read a beginner friendly guide to DNS, then explore the free computers and internet course on Khan Academy.
What is DNS, Cloudflare Khan Academy courseSources. Paul Baran, On Distributed Communications, RAND Corporation, 1964. Donald W. Davies, Proposal for a Digital Communication Network, National Physical Laboratory, 1966. Vinton G. Cerf and Robert E. Kahn, A Protocol for Packet Network Intercommunication, IEEE Transactions on Communications, vol. 22, 1974. Edsger W. Dijkstra, A Note on Two Problems in Connexion with Graphs, Numerische Mathematik, vol. 1, 1959. Paul Mockapetris, RFC 1034 and RFC 1035, Domain Names, 1987. Tim Berners-Lee, Information Management, A Proposal, CERN, 1989. IPv6 specification, RFC 2460, 1998.
This lesson is based on standard networking teaching material and the classroom experience of the author. The labs are simplified teaching models, and the example names and addresses come from ranges reserved for documentation.
