Chapter 15

Networks & the Internet

High School
At a glance
Core ideaThe Internet routes independent packets across layered protocols.
Key termTCP/IP layering — application, transport, internet, link.
You can…Trace a page load from DNS through TCP, IP and HTTP.
Watch outIP makes no guarantees — TCP adds order and reliability on top.
Theory

A 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:

LayerJobExamples
ApplicationWhat users' programs speakHTTP, DNS, SMTP
TransportEnd-to-end delivery between programsTCP, UDP
InternetAddressing & routing across networksIP
LinkOne physical hopEthernet, 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
Laptop Phone Router Internet Server packets hop device → router → Internet → server, and back the same way
A home network in miniature: local devices reach the wider Internet through one router, then on to any server.
Explanation

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.

Step 1DNSResolve the name to an IP address.
Step 2TCPOpen a reliable connection to that address.
Step 3HTTPSend the request for the resource.
Step 4IPRoute packets hop by hop across networks.
Step 5RenderReassemble the reply and draw the page.
Practical

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.

Q&A
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.

Concept mind map

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.

packetsIP addressTCPDNSHTTPlayered protocolsNetworks and Internet
Infographic

The process, step by step

Step 1DNS lookupResolve the site name to an IP address.
Step 2TCP connectOpen a reliable connection with the three-way handshake.
Step 3HTTP requestSend a GET request for the page over that connection.
Step 4IP routingPackets hop router to router to the server and back.
Step 5RenderThe browser assembles the response and shows the page.
Solved examples

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?

  1. Split into chunks under the limit.
  2. 3000 / 1000 = 3 chunks.

Example 2You type a web address. What happens first before any page data arrives?

  1. The name must become an IP address.
  2. That is a DNS lookup.
Practice problem set

Now you try

Work each one out first, then tap to reveal the worked answer.

1What is a packet?
A small, independent chunk of a message that is routed across the network and reassembled at the destination.
2What does DNS do?
It translates human-readable names like a website address into numeric IP addresses.
3What does TCP provide?
A reliable, ordered connection: it retransmits lost packets and puts them back in order.
4Name the four TCP/IP layers.
Application, transport, internet, and link.
5What does IP do?
It addresses and routes packets hop by hop from source to destination across networks.
6Why send data as independent packets?
Packets can take different routes, route around failures, and share links efficiently.