Skip to content

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 postLayerReal nameExample
✉️ The letter7 ApplicationHTTP (HyperText Transfer Protocol), DNS (Domain Name System) lookups/scores · score=52 (a web “send” request)
🔒 The locked box6 Presentation / 5 SessionTLS (Transport Layer Security) encryption, keeping the conversation openlocked with a shared key
🚪 Room number + page "1 of 3"4 TransportTCP (Transmission Control Protocol) or UDP (User Datagram Protocol)port 443, piece 1 of 3
🏠 Street address3 NetworkIP (Internet Protocol) addressto 198.51.100.20
📦 Courier envelope for one leg2 Data linkWi-Fi or Ethernet frame, MAC (Media Access Control) addressto: the router's hardware address
🚚 The van on the road1 Physicalradio waves, light in fibre, voltagesthe actual signal

Memory hook (top → bottom): All People Seem To Need Data Processing = Application, Presentation, Session, Transport, Network, Data link, Physical.

Visual Mental Model ​

Encapsulation: the app's letter gets a TCP header, an IP header and a Wi-Fi frame on the way down; a router swaps only the frame; the server unwraps bottom to top

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.
L7📝Coin Dashwrites the letterL4🚪Transportport + piece numberL3🏠Networkto / from addressL2 + L1✉️Data linknext-hop envelopeL3 box🧭Routeropens L1–L3 onlyL1 → L7🖥️Coin Dash serverunwraps all of itwrapwrapwrapradio wavesnew L2, same L3
  1. Wrap down (encapsulation): each layer adds its own header (label) around what it received from above.
  2. Hop: every router removes the layer 2 envelope, reads the layer 3 address, and adds a fresh layer 2 envelope for the next leg.
  3. 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 coversExamples
Application7, 6, 5HTTP, TLS, DNS, email
Transport4TCP, UDP
Internet3IP
Link2, 1Wi-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 ​

DeviceReads up toDecides by
SwitchLayer 2hardware (MAC) address
RouterLayer 3IP address
Layer 4 load balancer / firewallLayer 4IP address + port
Layer 7 load balancer / web serverLayer 7the 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 ​

ChoiceUpsideDownside
Many layers, each with one jobMix and match tech; easy to reason aboutEvery header adds bytes and a little processing
Small packets (~1,500 bytes)Fair sharing, cheap resendsBig files = thousands of headers
Routers read only layer 3Fast forwarding; your data stays privateRouters 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 →

Built for clear thinking and fast 2-minute refreshers.