SkillPilotAI

The 7 layers of the OSI model

The OSI (Open Systems Interconnection) model splits network communication into 7 layers, each with one job. It is the common language of network engineers and the best tool for troubleshooting a problem layer by layer.

2.1 Why is it used?

  • example.com shows "This site can't be reached": is it the cable, the IP, the port or the web server? Without structure you check everything randomly.
  • ISO published OSI in 1984 as a reference model to bring order to this chaos.
  • Each layer talks only to the layer above and below it, so devices from different vendors work together.
  • Engineers speak in OSI terms: "a Layer 7 issue", "a Layer 4 load balancer".
  • Mnemonic, 7 to 1: All People Seem To Need Data Processing (Application, Presentation, Session, Transport, Network, Data Link, Physical).

2.2 The 7 layers

LayerJobPDUProtocolsDevices
7 ApplicationApps meet the networkDataHTTP, DNS, SMTPProxy, L7 load balancer
6 PresentationFormat, encryption, compression, encodingDataTLS, JPEG(software)
5 SessionOpens, maintains and closes sessions (login, video call)DataSession control(software)
4 TransportEnd-to-end delivery; ports pick the applicationSegment (datagram in UDP)TCP, UDPFirewall (ports)
3 NetworkIP addresses and routing (best path between networks)PacketIP, ICMPRouter, L3 switch
2 Data LinkDelivery inside the same LAN with MAC; error detectionFrameEthernet, Wi-Fi, ARPSwitch, access point, bridge
1 PhysicalBits to signals on cable, fiber or radioBitsCable, fiber, Wi-Fi radioHub, repeater, cable
  • Top 3 (7, 6, 5): what the application sends and in what format.
  • Layer 4: which application (port), reliable (TCP) or fast (UDP).
  • Layer 3: which computer on which network (IP), and the route.
  • Layers 2 and 1: the next device on this LAN (MAC) and the physical signal.

2.3 How it works: encapsulation and decapsulation

Encapsulation on the laptop (192.168.22.20)
  1. 1.L7 HTTP: browser builds GET / (data)

  2. 2.L4 TCP: adds ports 36830 -> 80 (segment)

  3. 3.L3 IP: adds .20 -> .10 (packet)

  4. 4.L2 MAC: adds ea:ea -> 16:eb (frame)

  5. 5.L1: frame becomes bits 0101 on the wire

Every layer adds its own header on the way down

Decapsulation on the web server (192.168.22.10)
  1. 1.L1: bits received

  2. 2.L2: destination MAC 16:eb = mine, frame header removed

  3. 3.L3: destination IP .10 = mine, IP header removed

  4. 4.L4: port 80 -> hand data to the web server app

  5. 5.L7: reads GET / and replies HTTP 200 OK

The reverse happens on the receiver, bottom to top

2.4 PDU names

LayerPDU name
7, 6, 5 (Application, Presentation, Session)Data
4 TransportSegment (datagram in UDP)
3 NetworkPacket
2 Data LinkFrame
1 PhysicalBits

2.5 Which device reads up to which layer

  • Switch: Layer 2, looks only at the MAC address to pick the output port.
  • Router: Layer 3, looks at the destination IP to choose the next route and reduces TTL by 1.
  • Internet routers do the same; the IP address stays the same end to end.
  • Web server: opens all 7 layers and processes the HTTP request.
  • Firewall filters ports at Layer 4; proxies and L7 load balancers understand HTTP and DNS.

2.6 Practical: Layer 1 and Layer 2

Lab: a small Docker LAN with a client (192.168.22.20) and a web server (192.168.22.10).

Terminal
ethtool eth0ip link show eth0ip -4 addr show eth0curl -sv http://192.168.22.10/tcpdump -e -n -i eth0 -c 10 tcp port 80
Output
$ ethtool eth0    Speed: 10000Mb/s    Duplex: Full    Link detected: yes$ ip link show eth02: eth0@if243: <BROADCAST,MULTICAST,UP,LOWER_UP>    link/ether ea:ea:57:60:e5:ca brd ff:ff:ff:ff:ff:ff
  • ethtool = Layer 1: Link detected: yes, Speed 10000Mb/s, Full duplex.
  • ip link = Layer 2: the client's MAC address after link/ether (ea:ea:57:60:e5:ca).

2.7 Practical: Layers 3, 4 and 7

Output
$ ip -4 addr show eth0    inet 192.168.22.20/24 brd 192.168.22.255 scope global eth0$ curl -sv http://192.168.22.10/* Connected to 192.168.22.10 (192.168.22.10) port 80> GET / HTTP/1.1> Host: 192.168.22.10< HTTP/1.0 200 OK< Server: SimpleHTTP/0.6 Python/3.12.3< Content-Length: 23Hello from the OSI lab
  • ip addr = Layer 3: client IP 192.168.22.20/24.
  • Connected to ... port 80 = Layer 4, the TCP connection is up.
  • GET / and HTTP/1.0 200 OK with "Hello from the OSI lab" = Layer 7.

2.8 Practical: all layers in one frame (tcpdump -e)

Output
$ tcpdump -e -n -i eth0 -c 10 tcp port 80ea:ea:57:60:e5:ca > 16:eb:e4:30:4c:ac, ethertype IPv4  192.168.22.20.36830 > 192.168.22.10.80:  Flags [S], seq 344705618, length 0ea:ea:57:60:e5:ca > 16:eb:e4:30:4c:ac, ethertype IPv4  192.168.22.20.36830 > 192.168.22.10.80:  Flags [P.], length 76: HTTP: GET / HTTP/1.1
  • ea:ea:57:60:e5:ca > 16:eb:e4:30:4c:ac = Layer 2 MAC addresses.
  • 192.168.22.20.36830 > 192.168.22.10.80 = Layer 3 IP + Layer 4 port (.80).
  • Flags [S] = the TCP handshake starting; Flags [P.] carries HTTP: GET / = Layer 7 data.

2.9 Troubleshooting: bottom up

LayerWhat to check
L1Cable, link light
L2Wi-Fi connected or switch port up
L3IP address, ping the gateway
L4Is the port open?
L7DNS, the application
Bottom up found the problem
  1. 1.Laptop pings router 192.168.1.1: reply, L1 to L3 of the LAN are fine

  2. 2.Laptop pings 8.8.8.8: reply, routing to the internet works

  3. 3.DNS query to local DNS server 192.168.1.53: Server not found

  4. 4.The first failing test is the problem layer: Layer 7 DNS

Check from Layer 1 upward; the layer where a test fails is where the problem is

2.10 Common mistakes

  • Myth: the internet runs on the OSI model. Reality: the internet runs on TCP/IP; OSI is a reference model and a common language.
  • Saying a switch routes by IP: a switch is Layer 2 (MAC only); the router is Layer 3 and picks the route by IP.
  • Mixing up PDU names: segment (L4), packet (L3), frame (L2).
  • Random troubleshooting instead of bottom up.

2.11 Interview tips

  • OSI = ISO's 7-layer reference model, from Physical to Application, one job per layer.
  • Know the PDUs: data, segment, packet, frame, bits.
  • Switch = Layer 2, router = Layer 3, firewall ports = Layer 4, L7 load balancer = HTTP.
  • Its biggest use is troubleshooting: isolate the problem layer by layer, bottom up.
  • Mention that the real internet runs on TCP/IP; OSI is the reference model.