Appearance
Packets & Layers (the OSI Model)
Season 2 · Note 2
In Plain English (30-Second Refresher)
TL;DR
Data never travels as one big blob. It's cut into packets (about 1,500 bytes each), and each packet is wrapped in envelopes inside envelopes, one per job.
- The OSI (Open Systems Interconnection) model numbers those jobs as 7 layers: 7 = what the app says … 1 = the raw signal.
- Going down the layers = wrapping (encapsulation). Coming up at the other end = unwrapping.
- Each device only opens the layers it needs: a router reads up to layer 3 (the IP, Internet Protocol, address) and never opens your letter.
- Real software uses the simpler 4-layer TCP/IP model (named after TCP, the Transmission Control Protocol, and IP); OSI numbers survive as vocabulary ("L4", "L7").
The Mission We Follow
Coin Dash wants to send one line, score=52, to its server abroad. On the wire, that line is wearing five envelopes. This note explains each one, and who is allowed to open it.
Real-World Analogy: A Letter in a Box in a Parcel 📮
You write a letter, lock it in a box, label the box with a room number, put it in a parcel with a street address, and hand it to a courier who only goes to the next depot. Each depot swaps the courier envelope but never opens the box.
| In the post | Layer | Real name | Example |
|---|---|---|---|
| ✉️ The letter | 7 Application | HTTP (HyperText Transfer Protocol), DNS (Domain Name System) lookups | /scores · score=52 (a web “send” request) |
| 🔒 The locked box | 6 Presentation / 5 Session | TLS (Transport Layer Security) encryption, keeping the conversation open | locked with a shared key |
| 🚪 Room number + page "1 of 3" | 4 Transport | TCP (Transmission Control Protocol) or UDP (User Datagram Protocol) | port 443, piece 1 of 3 |
| 🏠 Street address | 3 Network | IP (Internet Protocol) address | to 198.51.100.20 |
| 📦 Courier envelope for one leg | 2 Data link | Wi-Fi or Ethernet frame, MAC (Media Access Control) address | to: the router's hardware address |
| 🚚 The van on the road | 1 Physical | radio waves, light in fibre, voltages | the actual signal |
Memory hook (top → bottom): All People Seem To Need Data Processing = Application, Presentation, Session, Transport, Network, Data link, Physical.
Visual Mental Model
How It Works (Interactive Animated Flow)
Wrapped, Routed, Unwrapped
Follow one packet down the layers, through a router, and up again
🎯 Mission Send “score = 52” from Coin Dash on your laptop to the Coin Dash server.
- Wrap down (encapsulation): each layer adds its own header (label) around what it received from above.
- Hop: every router removes the layer 2 envelope, reads the layer 3 address, and adds a fresh layer 2 envelope for the next leg.
- Unwrap up (decapsulation): the receiver peels layers 1 → 7 until the app gets the original message.
OSI (7) vs TCP/IP (4): What Actually Runs
| TCP/IP layer (real software) | OSI layers it covers | Examples |
|---|---|---|
| Application | 7, 6, 5 | HTTP, TLS, DNS, email |
| Transport | 4 | TCP, UDP |
| Internet | 3 | IP |
| Link | 2, 1 | Wi-Fi, Ethernet, fibre |
OSI is the shared vocabulary; TCP/IP is the implementation. Layers 5 and 6 rarely exist as separate pieces of code.
Who Reads Which Layer
| Device | Reads up to | Decides by |
|---|---|---|
| Switch | Layer 2 | hardware (MAC) address |
| Router | Layer 3 | IP address |
| Layer 4 load balancer / firewall | Layer 4 | IP address + port |
| Layer 7 load balancer / web server | Layer 7 | the actual request (path, headers) |
Why Packets? Why Layers?
- Packets share the road. Millions of conversations interleave on the same cables; a lost packet costs one resend, not the whole file.
- Size limit: a layer 2 envelope carries at most about 1,500 bytes (the MTU, maximum transmission unit). Bigger messages are split.
- Layers let parts change independently. Swap Wi-Fi for 5G or fibre and nothing above layer 2 notices. Add TLS and routers don't care.
Trade-offs
| Choice | Upside | Downside |
|---|---|---|
| Many layers, each with one job | Mix and match tech; easy to reason about | Every header adds bytes and a little processing |
| Small packets (~1,500 bytes) | Fair sharing, cheap resends | Big files = thousands of headers |
| Routers read only layer 3 | Fast forwarding; your data stays private | Routers can't make app-aware decisions (that's a layer 7 box's job) |
Common Gotchas
Watch Out For
- "Layer 7" means application, not "7 servers". L4/L7 describe how deep a box looks inside the packet.
- OSI is a model, not code. No operating system has seven separate layers; don't hunt for "the session layer" in real code.
- The IP address stays the same end to end; the layer 2 address changes every hop. (A home router's address swap, NAT (Network Address Translation), is the one exception, covered in the next note.)
- Headers cost space. A 1-byte message still carries ~50–70 bytes of envelopes.
Quick Self-Check (Restore Your Memory)
1. Your packet passes through a router. Which envelope does the router replace?
Only the layer 2 envelope (the Wi-Fi or Ethernet frame). It reads layer 3 (the IP address) to choose the next hop and leaves layers 4–7 sealed.
2. Put these in order, outside to inside: IP address, Wi-Fi frame, HTTP request, TCP port.
Wi-Fi frame (L2) → IP address (L3) → TCP port (L4) → HTTP request (L7). Wrapping happens in the opposite order.
3. What does "a layer 4 load balancer" tell you?
It routes using only addresses and ports (layer 4). It never reads the request itself, so it can't route /scores and /images differently. A layer 7 one can.
🎬 Now Watch It Happen
2-minute episode
Ride along as the packet while it's dressed layer by layer, half-opened at the router, and unwrapped at the server. S2 · E2 — Dressed in Layers →