Networks & the Internet
High SchoolA network connects computers so they can exchange data. The Internet is a network of networks that works by packet switching: messages are chopped into small packets, each routed independently and reassembled at the destination. This is robust — packets flow around failures — and efficient, since links are shared rather than dedicated.
Complexity is tamed by layering. The TCP/IP model has four layers, each using the one below and serving the one above:
| Layer | Job | Examples |
|---|---|---|
| Application | What users' programs speak | HTTP, DNS, SMTP |
| Transport | End-to-end delivery between programs | TCP, UDP |
| Internet | Addressing & routing across networks | IP |
| Link | One physical hop | Ethernet, Wi-Fi |
IP gives every device an address and routes packets, but makes no guarantee of delivery or order. TCP layers reliability on top — acknowledgements, retransmission and ordering — while UDP stays lightweight for speed. DNS translates human names like jupiter2u.com into IP addresses. HTTP is the request/response protocol of the Web.
TCP — reliable stream
- Ordered, guaranteed byte stream
- Acknowledgements & retransmission
- Congestion control
- Web pages, files, email
UDP — fire and forget
- Independent datagrams
- No ordering, no retransmission
- Lower latency, less overhead
- Live video, gaming, DNS
Layering is the same abstraction principle as functions and objects, applied to communication. Each layer offers a clean service to the one above and hides its own mechanism. Your browser speaks HTTP without caring whether the bytes travel over fibre, Wi-Fi or satellite — the lower layers handle that. Swap Wi-Fi for Ethernet and nothing above the link layer changes. This separation of concerns is why the Internet could evolve for fifty years without a rewrite.
TCP's reliability is a beautiful illusion built on unreliable IP. IP packets can vanish, duplicate, or arrive out of order. TCP numbers every byte, waits for acknowledgements, retransmits what goes unacknowledged, and reorders arrivals — presenting the application with a clean, ordered stream, as if a private wire connected the two programs. It also does congestion control, backing off when the network is busy so the shared Internet doesn't collapse.
Mental model. When you load a page: DNS resolves the name → TCP opens a reliable connection → HTTP requests the resource → IP routes each packet hop by hop → TCP reassembles → your browser renders. Six protocols, one click.
Since we can't run real hardware here, we simulate the two ideas at the heart of reliable networking: splitting a message into packets, and reassembling them in order despite arriving scrambled — exactly what TCP's sequence numbers achieve.
def packetize(message, size=4):
"""Split a message into numbered packets (like TCP segmenting a stream)."""
packets = []
seq = 0
for start in range(0, len(message), size):
chunk = message[start:start + size]
packets.append({"seq": seq, "data": chunk}) # sequence number + payload
seq += 1
return packets
def reassemble(packets):
"""Reorder by sequence number, then concatenate -> reliable ordered stream."""
packets_in_order = sorted(packets, key=lambda p: p["seq"])
return "".join(p["data"] for p in packets_in_order)
msg = "HELLO INTERNET"
packets = packetize(msg)
print(packets)
# [{'seq':0,'data':'HELL'}, {'seq':1,'data':'O IN'},
# {'seq':2,'data':'TERN'}, {'seq':3,'data':'ET'}]
# Simulate the network delivering them OUT of order:
scrambled = [packets[2], packets[0], packets[3], packets[1]]
print(reassemble(scrambled)) # -> "HELLO INTERNET" (order restored!)
The sequence number is the whole trick. IP may deliver packets in any order, but because each carries its position, the receiver can sort them back into the original stream — and detect a gap (a lost packet) by a missing number, triggering a retransmission request.
Q1 Why break messages into packets instead of sending them whole?
Packets let many conversations share the same links efficiently (interleaving rather than monopolising), allow each packet to route around failures independently, and make error recovery cheap — a corrupted packet is re-sent, not the entire file. This resilience is exactly what the Internet was designed for.
Q2 What's the difference between TCP and UDP?
TCP is reliable and ordered: it guarantees every byte arrives, in sequence, retransmitting losses — ideal for web pages, files, email. UDP is a lightweight "fire and forget" — no acknowledgements, no ordering, no retransmission — which makes it faster and lower-latency, ideal for live video, gaming and DNS, where a slightly late packet is worse than a lost one.
Q3 What does DNS actually do?
DNS is the Internet's phone book: it translates human-friendly domain names (jupiter2u.com) into the numeric IP addresses routers use (like 93.184.216.34). It's a distributed, hierarchical system — root servers point to top-level-domain servers, which point to the authoritative server for each domain — so no single machine holds the whole map.
Q4 Why is layering so important to the Internet's design?
It decouples innovation. Because each layer only depends on the clean interface of the one below, you can replace Wi-Fi with 5G at the link layer, or add HTTPS at the application layer, without touching the others. New technologies slot in at one level while everything above and below keeps working — the reason a network designed in the 1970s still runs today's world.
How the ideas connect
Every key idea in this chapter, branching from the core concept — use it to see the whole picture at a glance.
The process, step by step
Worked problems, step by step
Follow each solution line by line, then try to reproduce it on paper before moving on.
Example 1A message is 3000 bytes but the max packet is 1000 bytes. How is it sent?
- Split into chunks under the limit.
- 3000 / 1000 = 3 chunks.
Example 2You type a web address. What happens first before any page data arrives?
- The name must become an IP address.
- That is a DNS lookup.
Now you try
Work each one out first, then tap to reveal the worked answer.