Foundations

The OSI Model

seven layers that describe how a network actually talks

2 min readupdated by Syed Khaleel Ahmed

When you open a web page, a lot happens that you never see: a cable or radio signal carries bits, devices find each other, data is split into pieces, and an application finally makes sense of it. The OSI model is a way of describing those jobs as seven layers, each one relying on the layer below it.[1]

The seven layers

From the bottom up:

  1. Physical. Cables, radio and electrical signals. Bits on a wire.
  2. Data link. Moving frames between devices on the same local network. MAC addresses, switches, Wi-Fi.
  3. Network. Addressing and routing between networks. IP addresses and routers.
  4. Transport. Reliable (or fast) delivery between two programs. TCP and UDP, port numbers.
  5. Session. Starting, keeping and ending a conversation.
  6. Presentation. How data is represented: formats, character sets, encryption and compression.
  7. Application. The protocols that programs use to talk, such as HTTP, DNS and SMTP.

A common memory aid, from the top down, is "All People Seem To Need Data Processing".

OSI versus TCP/IP

The real internet runs on the TCP/IP model, which has fewer layers (roughly link, internet, transport and application).[2] OSI is a teaching and troubleshooting tool, not a description of how any one program is built. Layers 5 to 7 are often blurred together in practice. You still need it, because people across the industry use "layer 2" or "layer 7" as shared shorthand.

Why security people care

Attacks and defenses are easier to talk about once you can say where they live:

  • Layer 2: ARP spoofing, MAC flooding, rogue Wi-Fi access points.
  • Layer 3: IP spoofing, route hijacking.
  • Layer 4: SYN floods and port scans.
  • Layer 7: SQL injection, cross-site scripting, and most web attacks.

A traditional firewall mostly looks at layers 3 and 4 (addresses and ports). A web application firewall looks at layer 7 (the content of web requests). Neither replaces the other, which is one reason defense in depth uses several tools.

Use it as a troubleshooting ladder

When something is not working, walk the layers: is it plugged in or on Wi-Fi (1 and 2)? Does it have an IP address and a route (3)? Is the port reachable (4)? Is the application behaving (7)? Defenders do the same when investigating: which layer did the suspicious thing happen at?

Sources

  1. Cloudflare Learning Center: What is the OSI model?
  2. IETF RFC 1122: Requirements for Internet Hosts, Communication Layers

Test yourself

My notes

Private — saved only on this device, never sent anywhere.