Each layer wraps the data.
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#
Seven layers, each adds one wrapper.
Numbered from the bottom, the wire, to the top, your app:
| # | Layer | Its job | In the parcel |
|---|---|---|---|
| 7 | Application | the app's own message, like a chat or a web page | the note "hi" |
| 6 | Presentation | the format, and encryption (scrambling it so only your friend can read it) | the lock |
| 5 | Session | which conversation this belongs to | the chat tag |
| 4 | Transport | split into numbered pieces so order holds | the numbered box |
| 3 | Network | the IP address, and which way to go next between networks | the address label |
| 2 | Data link | carries it across one link, to the next box, by MAC address | the ride to the next stop |
| 1 | Physical | the actual signal: 1s and 0s on a wire or radio | the 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 layer | Covers OSI layers |
|---|---|
| Application | 7, 6 and 5: Application, Presentation, Session |
| Transport | 4: Transport |
| Internet | 3: 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 it | What you saw |
|---|---|
| OSI model | seven layers, Physical at the bottom, Application at the top |
| Encapsulation | each layer adds its header on the way down |
| PDU names | data, segment, packet, frame, bits |
| Network layer | picks the path between networks, by IP address |
| Device layers | hub 1, switch 2, router 3 |
| TCP/IP model | four 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.