The 7 OSI layers with PDUs, functions, protocols and devices; encapsulation/decapsulation; OSI vs the TCP/IP model; what-layer-is-X (ARP, MPLS, VXLAN, TLS, LBs); and layer-by-layer troubleshooting.
The OSI model is the shared vocabulary of networking: seven layers, each doing one job and talking only to the layers directly above and below it. You rarely implement "pure OSI," but every interview and every troubleshooting session is framed in its terms — "that's a Layer 2 problem," "the LB works at Layer 4," "TLS sits around Layer 6."
Two things to nail: what each layer does (and its PDU + example protocols), and how encapsulation walks the stack — each layer wraps the layer above in its own header on the way down, and strips it on the way up.
| # | Layer | PDU | Job | Examples | Device |
|---|---|---|---|---|---|
| 7 | Application | Data | App-level protocols the user/app speaks | HTTP, DNS, SMTP, gRPC, SSH | — |
| 6 | Presentation | Data | Encoding, serialization, encryption/compression | TLS, ASCII/UTF-8, JPEG, ASN.1 | — |
| 5 | Session | Data | Set up / maintain / tear down sessions | RPC, NetBIOS, TLS handshake state | — |
| 4 | Transport | Segment / Datagram | End-to-end delivery, ports, reliability | TCP, UDP, QUIC | L4 load balancer / firewall |
| 3 | Network | Packet | Logical addressing & routing between networks | IP, ICMP, OSPF, BGP | Router, L3 switch |
| 2 | Data Link | Frame | Local delivery on a link; MAC addressing, error check | Ethernet, 802.1Q, ARP, PPP | Switch, bridge, NIC |
| 1 | Physical | Bit / Symbol | Signals on the medium | Copper, fiber, RJ45, SFP, PAM4 | Hub, cable, transceiver |
Mnemonic: "All People Seem To Need Data Processing" (7→1).
Sending is top-down; each layer adds its header (L2 also adds a trailer, the FCS). Receiving is bottom-up; each layer strips its own header and hands the payload up. The receiver's layer N only ever reads layer N's header — that's the whole point.
send (host A) wire receive (host B)
L7 data L7 data
L4 [TCP | data] L4 strip TCP
L3 [IP | TCP | data] L3 strip IP
L2 [Eth | IP | TCP | data | FCS] ── bits ──▶ L2 strip Eth/FCS
L1 0101110100... L1 recover bits
Each layer's "next-protocol" field tells the receiver what the payload is: EtherType (L2→L3), IP Protocol / IPv6 Next Header (L3→L4), TCP/UDP port (L4→app). See Protocol Headers.
The real stack is the 4-layer TCP/IP model; OSI is the reference overlay on top of it.
| TCP/IP (4) | OSI layers | Examples |
|---|---|---|
| Application | 7–5 | HTTP, DNS, TLS, gRPC |
| Transport | 4 | TCP, UDP |
| Internet | 3 | IP, ICMP |
| Link (Network Access) | 2–1 | Ethernet, ARP, PHY |
A favorite trap — several protocols don't sit cleanly on one layer:
| Thing | Layer | Why |
|---|---|---|
| Switch | 2 | Forwards frames by MAC; an "L3 switch" also routes. |
| Router | 3 | Forwards packets by IP / longest-prefix match. |
| ARP | 2–3 boundary | Resolves IP (L3) to MAC (L2); rides in Ethernet, not IP. |
| ICMP | 3 | Carried in IP (proto 1), no ports — it is L3 signalling. |
| MPLS | "2.5" | Shim between L2 and L3. |
| VXLAN | L2 over L4 | Wraps an Ethernet frame in UDP — L2 payload, L4 transport. |
| TLS | ~6 (over L4) | Presentation-ish encryption riding on TCP. |
| BGP / DNS | 7 | Application protocols over TCP/UDP (BGP on TCP 179). |
| Load balancer | 4 or 7 | L4 balances by IP/port; L7 reads HTTP host/path/cookies. |
| Firewall | 3–7 | Stateless (L3/4 ACLs) up to next-gen (L7 app inspection). |
The model is a debugging checklist. Two directions:
Map symptoms to layers: CRC errors → L1/L2; ARP incomplete → L2/L3; "no route to host" → L3; connection refused / timeout → L4 (port/firewall); TLS/cert error → L6; HTTP 5xx → L7. See Troubleshooting Scenarios and Packet Life: google.com.