Course outline · 0% complete

0/30 lessons0%

Course overview →

Why networks are built in layers

lesson 1-3 · ~10 min · 3/30

The combinatorial problem layering solves

Suppose you must connect m kinds of applications over n kinds of links. Email, web, video, file transfer, over Ethernet, Wi-Fi, fiber, 5G, satellite. Written directly, each application needs custom code for each link type, so you write m × n implementations. Five applications over five links is 25 pieces of software, and every new link type means five more.

Layering replaces the grid with a stack. Each application talks to one common middle layer, and each link technology implements that same middle layer. Now you write m + n pieces, and a new link type costs exactly one. Five plus five is 10, not 25.

That middle layer is IP, and this trick is the single reason the internet absorbed technologies nobody had invented when it was designed. A browser written in 1994 works over a 2020s 5G radio because both sides only ever agreed about IP.

What a layer actually is

A layer is two things:

1. A service it offers to the layer above, stated as a promise. Example: "give me bytes and a destination address, I will try to deliver them." 2. A protocol it speaks with its peer layer on the other host, meaning the same layer on the machine at the far end.

Two rules make the stack work, and both are worth memorizing:

- A layer only ever calls the layer directly below it, and only ever offers service to the layer directly above it. - A layer's header is written for its peer on the other host, not for the layers around it.

The postal analogy is exact. You write a letter (application layer). You put it in an envelope with a street address (network layer). The post office puts the envelope in a truck bag headed to the next depot (link layer). The truck driver never reads your letter, and you never chose the truck. Each layer reads only its own label.

applicationtransportnetworklinkapplicationtransportnetworklinkreal bits on a real wiresenderreceiverdashed lines are peer conversations, not wires
Data goes down the stack on the sender, across one link at a time, and up the stack on the receiver. Each layer talks only to its peer.

What layering costs, and where it leaks

Layering is not free, and being honest about the costs makes the rest of the course easier to read.

BenefitMatching cost
Swap Wi-Fi for Ethernet, apps unchangedevery layer adds header bytes
Debug one layer at a timea fault can hide one layer down
Many teams work independentlyduplicated work, several checksums
New technology plugs ininformation the layers hide is lost

The last row is the interesting one. A layer hides detail from the layer above, and sometimes the layer above needed that detail. Three leaks you will meet later in this course:

- MTU: the link layer's size limit is supposed to be invisible, but a large packet that cannot be split will be dropped, and the sender has to guess why. - NAT: the network layer promises addresses mean one host, and NAT breaks that so completely that Unit 6 exists to explain it. - Wireless loss: TCP treats loss as congestion, but on Wi-Fi loss is often radio interference, so TCP slows down for no reason.

Keep the model, expect the leaks. The layers are the map, not the terrain.