← Interview Prep

The OSI Model — Layer by Layer

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.

The seven layers

#LayerPDUJobExamplesDevice
7ApplicationDataApp-level protocols the user/app speaksHTTP, DNS, SMTP, gRPC, SSH
6PresentationDataEncoding, serialization, encryption/compressionTLS, ASCII/UTF-8, JPEG, ASN.1
5SessionDataSet up / maintain / tear down sessionsRPC, NetBIOS, TLS handshake state
4TransportSegment / DatagramEnd-to-end delivery, ports, reliabilityTCP, UDP, QUICL4 load balancer / firewall
3NetworkPacketLogical addressing & routing between networksIP, ICMP, OSPF, BGPRouter, L3 switch
2Data LinkFrameLocal delivery on a link; MAC addressing, error checkEthernet, 802.1Q, ARP, PPPSwitch, bridge, NIC
1PhysicalBit / SymbolSignals on the mediumCopper, fiber, RJ45, SFP, PAM4Hub, cable, transceiver

Mnemonic: "All People Seem To Need Data Processing" (7→1).

Encapsulation & decapsulation

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.

OSI vs the TCP/IP model

The real stack is the 4-layer TCP/IP model; OSI is the reference overlay on top of it.

TCP/IP (4)OSI layersExamples
Application7–5HTTP, DNS, TLS, gRPC
Transport4TCP, UDP
Internet3IP, ICMP
Link (Network Access)2–1Ethernet, ARP, PHY

"What layer does X operate at?"

A favorite trap — several protocols don't sit cleanly on one layer:

ThingLayerWhy
Switch2Forwards frames by MAC; an "L3 switch" also routes.
Router3Forwards packets by IP / longest-prefix match.
ARP2–3 boundaryResolves IP (L3) to MAC (L2); rides in Ethernet, not IP.
ICMP3Carried in IP (proto 1), no ports — it is L3 signalling.
MPLS"2.5"Shim between L2 and L3.
VXLANL2 over L4Wraps an Ethernet frame in UDP — L2 payload, L4 transport.
TLS~6 (over L4)Presentation-ish encryption riding on TCP.
BGP / DNS7Application protocols over TCP/UDP (BGP on TCP 179).
Load balancer4 or 7L4 balances by IP/port; L7 reads HTTP host/path/cookies.
Firewall3–7Stateless (L3/4 ACLs) up to next-gen (L7 app inspection).

Troubleshooting by layer

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.

Likely interview questions

Related: Protocol Headers · Packet Life: google.com · Life of a Packet.