You've now followed a message all the way: cut into packets, given an address, switched and routed hop by hop, sent to a name that DNS turned into a number. That's a lot of separate jobs for one "hi".

Who does which job, and in what order?

See it#

Send "hi" to a friend once more. Tap play. This time, watch it get packed like a courier parcel, one piece at a time, before it leaves your phone, and unpacked on the other side.

Seven pieces went on, in a fixed order: the note, a lock, a chat tag, a numbered box, an address label, a ride to the next stop, and finally a stream of 1s and 0s. Your friend's phone took them off in exactly the reverse order, last on, first off, until only "hi" was left.

Name it#

Each of those seven pieces was added by a separate layer that does one job and trusts the layers below to do theirs. The OSI model describes networking as seven layers, each adding its own wrapper to the data on the way down and removing it on the way up.

Adding wrappers on the way down is called encapsulation; taking them off on the way up is decapsulation. OSI stands for Open Systems Interconnection.

How it works#

You already know most of these layers from the last four lessons. Here they are with their names.

1. The seven layers#

Numbered from the bottom, the wire, to the top, your app:

#LayerIts jobIn the parcel
7Applicationthe app's own message, like a chat or a web pagethe note "hi"
6Presentationthe format, and encryption (scrambling it so only your friend can read it)the lock
5Sessionwhich conversation this belongs tothe chat tag
4Transportsplit into numbered pieces so order holdsthe numbered box
3Networkthe IP address, and which way to go next between networksthe address label
2Data linkcarries it across one link, to the next box, by MAC addressthe ride to the next stop
1Physicalthe actual signal: 1s and 0s on a wire or radiothe road of bits

A common way to remember them from the bottom up: Please Do Not Throw Sausage Pizza Away, for Physical, Data link, Network, Transport, Session, Presentation, Application. The usual slip is swapping Session and Presentation: Session sits right above Transport.

Some layers you've met already. DNS, from the last lesson, works at the Application layer: the lookup is itself a small message from an app, packed the same seven ways. The Network layer is where routers work: when your 'hi' leaves your ISP's network for your friend's, it's the Network layer, reading the IP address, that picks which network it goes to next. The Data link layer only gets it across one link at a time. (Routers and next hops are the Routers and switches lesson.)

2. Each wrapper gives the data a new name#

On the way down, each layer adds its own header, a few bytes of labels, in front of what it got from above. The unit has a different name at each layer:

  • At the Application layer it's just data.
  • The Transport layer adds its header, for example a TCP header, and makes a segment.
  • The Network layer wraps the segment in an IP header and makes a packet.
  • The Data link layer wraps the packet with MAC addresses and makes a frame. It also adds a short trailer at the end, a check value that lets the next box spot a damaged frame.
  • The Physical layer sends the frame as bits.

So the order is data, segment, packet, frame, bits. In What is a network we called every piece a packet, and people still do day to day. Strictly, the numbered piece is a segment, made by Transport; it becomes a packet once IP puts the address on it. A frequent mistake is to swap segment and packet. Remember that IP wraps the TCP segment, not the other way round. (TCP itself comes later in the roadmap.)

Interviews call these five names PDUs, protocol data units: just the name of the data at each layer.

3. Every box works up to its own layer#

The receiving phone runs the stack upwards, each layer reading and removing only its own header. Boxes in the middle only open the parcel as far as they need:

  • A hub works at layer 1, Physical. It only repeats signals and reads no address.
  • A switch works at layer 2, Data link. It reads MAC addresses in frames.
  • A router works at layer 3, Network. It reads IP addresses in packets.

That's the layer number behind each box you met in Routers and switches.

4. The model the internet actually runs, TCP/IP#

OSI is the model for learning and talking about networks. The internet itself runs on the TCP/IP model, which folds the same jobs into four layers:

TCP/IP layerCovers OSI layers
Application7, 6 and 5: Application, Presentation, Session
Transport4: Transport
Internet3: Network
Link (network access)2 and 1: Data link, Physical

TCP/IP has no separate Session or Presentation layer: those jobs are done by the application, or by its Application layer. Transport stays its own layer in both models. (Some books draw TCP/IP with five layers, keeping Physical separate. The idea is the same.)

Why it matters#

Layers are how network problems are found and how network jobs are split. "Is it the cable, the Wi-Fi, the IP address, the DNS or the app?" is a walk up the layers, bottom first. Engineers say "a layer 2 problem" or "a layer 3 device", and every device is built to work up to a known layer. Each layer can change without the others noticing: you switch from Wi-Fi to mobile data, which changes layers 1 and 2, and your WhatsApp chat carries on.

In interviews, the layer questions check these:

Interviews call itWhat you saw
OSI modelseven layers, Physical at the bottom, Application at the top
Encapsulationeach layer adds its header on the way down
PDU namesdata, segment, packet, frame, bits
Network layerpicks the path between networks, by IP address
Device layershub 1, switch 2, router 3
TCP/IP modelfour layers; its Application layer covers OSI 5 to 7

What to remember#

  • OSI has seven layers, bottom up: Physical, Data link, Network, Transport, Session, Presentation, Application.
  • Going down, each layer adds a header: data, segment, packet, frame, bits. The receiver unwraps in reverse.
  • The Network layer picks the path between networks; the Data link layer crosses one link at a time.
  • A hub is layer 1, a switch layer 2, a router layer 3.
  • TCP/IP has four layers; its Application layer does the work of OSI 5, 6 and 7.