Topic Overview

OSI Model (7 Layers)

Learn the OSI 7-layer model for understanding network communication protocols.

Beginner10 min read

OSI Model (7 Layers)

Why This Matters

Think of the OSI model like a postal system. When you send a letter, it goes through multiple steps: you write it (application), format it (presentation), address it (session), put it in an envelope (transport), add routing info (network), put it in a mail truck (data link), and it travels physically (physical). The OSI model does the same for network communication—it breaks down how data travels from your application to the network.

This matters because understanding the OSI model helps you debug network issues. If your application can't connect, is it an application problem (Layer 7), a network problem (Layer 3), or a physical problem (Layer 1)? Knowing which layer is involved helps you narrow down the problem. Also, many interview questions reference these layers.

In interviews, when someone asks "At which OSI layer does a router operate?", they're testing whether you understand the model. Do you know what each layer does? Can you identify which layer a device or protocol operates at? Most engineers don't. They just know "HTTP is application layer" but can't explain why.

What Engineers Usually Get Wrong

Most engineers think "the OSI model is just theory—I don't need to know it." But the OSI model is practical. It helps you understand how network protocols work together. When you use HTTP (Layer 7) over TCP (Layer 4) over IP (Layer 3), understanding the layers helps you understand the stack.

Engineers also confuse the OSI model with the TCP/IP model. The OSI model has 7 layers, while TCP/IP has 4-5 layers. They're similar but not identical. Understanding both helps you understand how real networks work (TCP/IP) and how they're conceptualized (OSI).

How This Breaks Systems in the Real World

A service was having network connectivity issues. The team spent hours debugging at the application layer (Layer 7), checking HTTP requests and responses. But the problem was actually at the network layer (Layer 3)—routing was misconfigured. Understanding the OSI model would have helped them narrow down the problem faster. The fix? Check each layer systematically, starting from the physical layer and working up.

Another story: A service was using a load balancer but didn't understand which layer it operated at. They configured it incorrectly, thinking it worked at Layer 7 (application) when it actually worked at Layer 4 (transport). This caused routing issues. The fix? Understand which layer your tools operate at, and configure them accordingly.


The 7 Layers

Layer 7: Application

Purpose: Interface between user and network Examples: HTTP, HTTPS, FTP, SMTP, DNS Data unit: Message

Layer 6: Presentation

Purpose: Data translation, encryption, compression Examples: SSL/TLS, JPEG, MPEG Data unit: Message

Layer 5: Session

Purpose: Establish, manage, terminate sessions Examples: NetBIOS, RPC Data unit: Message

Layer 4: Transport

Purpose: End-to-end communication, error recovery Examples: TCP, UDP Data unit: Segment (TCP) / Datagram (UDP)

Layer 3: Network

Purpose: Routing, logical addressing Examples: IP, ICMP, OSPF, BGP Data unit: Packet

Purpose: Framing, error detection, MAC addressing Examples: Ethernet, PPP, Switch Data unit: Frame

Layer 1: Physical

Purpose: Physical transmission of bits Examples: Cables, hubs, repeaters Data unit: Bit


Data Flow

Application Data
[Layer 7] Adds application header
[Layer 6] Adds presentation header
[Layer 5] Adds session header
[Layer 4] Adds transport header (TCP/UDP)
[Layer 3] Adds network header (IP)
[Layer 2] Adds data link header (Ethernet)
[Layer 1] Transmits bits over physical medium

Encapsulation: Each layer adds its header to the data from the layer above.

Decapsulation: Each layer removes its header and passes data to the layer above.


Examples

HTTP Request Flow

1. Application Layer: Browser creates HTTP request
   GET /index.html HTTP/1.1
   Host: example.com

2. Transport Layer: TCP adds port numbers
   Source Port: 49152
   Dest Port: 80

3. Network Layer: IP adds IP addresses
   Source IP: 192.168.1.100
   Dest IP: 93.184.216.34

4. Data Link Layer: Ethernet adds MAC addresses
   Source MAC: 00:1B:44:11:3A:B7
   Dest MAC: 00:0C:29:AB:CD:EF

5. Physical Layer: Transmits bits over cable

Common Pitfalls

  • Confusing layers: Not understanding which layer handles what. Fix: Remember "All People Seem To Need Data Processing" (Application to Physical)
  • Mixing OSI and TCP/IP: TCP/IP has 4 layers, OSI has 7. Fix: Understand both models
  • Layer boundaries: Some protocols span multiple layers. Fix: Focus on primary function
  • Not understanding encapsulation: How data flows through layers. Fix: Trace a packet through each layer

Interview Questions

Beginner

Q: What is the OSI model and why is it important?

A: The OSI model is a 7-layer conceptual framework that standardizes network communication functions.

Why important:

  • Standardization: Common language for networking
  • Troubleshooting: Identify which layer has issues
  • Design: Understand how protocols work together
  • Education: Foundation for networking concepts

Layers (top to bottom): Application, Presentation, Session, Transport, Network, Data Link, Physical.


Intermediate

Q: Explain how an HTTP request flows through the OSI layers. What happens at each layer?

A:

Flow:

  1. Application (Layer 7): Browser creates HTTP request

    GET /page.html HTTP/1.1
    Host: example.com
    
  2. Presentation (Layer 6): Data encoding/compression (if any)

  3. Session (Layer 5): Establishes session (HTTP is stateless, minimal here)

  4. Transport (Layer 4): TCP adds:

    • Source port (ephemeral, e.g., 49152)
    • Destination port (80 for HTTP)
    • Sequence numbers, ACK numbers
    • Creates TCP segment
  5. Network (Layer 3): IP adds:

    • Source IP (192.168.1.100)
    • Destination IP (93.184.216.34)
    • Creates IP packet
  6. Data Link (Layer 2): Ethernet adds:

    • Source MAC address
    • Destination MAC (router's MAC)
    • Creates Ethernet frame
  7. Physical (Layer 1): Transmits bits over cable/wireless

Reverse on receiving side: Each layer removes its header and passes to layer above.


Senior

Q: Design a network troubleshooting system that identifies issues at different OSI layers. How do you detect and diagnose problems at each layer?

A:

Design:

1class OSILayerDiagnostics {
2 // Layer 1 (Physical): Check physical connectivity
3 async diagnosePhysical(): Promise<Diagnostic> {
4 const checks = {
5 cableConnected: await this.checkCable(),
6 linkUp: await this.checkLinkStatus(),
7 signalStrength: await this.getSignalStrength()
8 };
9
10 if (!checks.cableConnected) {
11 return { layer: 1, issue: 'Cable not connected' fix

Tools for each layer:

  • Layer 1: ethtool, link status LEDs
  • Layer 2: arp, ifconfig, switch logs
  • Layer 3: ping, traceroute, ip route
  • Layer 4: netstat, ss, telnet
  • Layer 5-7: dig, curl, wireshark

Failure Stories You'll Recognize

The Wrong Layer Debugging: A service was having network connectivity issues. The team spent hours debugging at the application layer (Layer 7), checking HTTP requests and responses. But the problem was actually at the network layer (Layer 3)—routing was misconfigured. Understanding the OSI model would have helped them narrow down the problem faster. The fix? Check each layer systematically, starting from the physical layer and working up.

The Load Balancer Misconfiguration: A service was using a load balancer but didn't understand which layer it operated at. They configured it incorrectly, thinking it worked at Layer 7 (application) when it actually worked at Layer 4 (transport). This caused routing issues. The fix? Understand which layer your tools operate at, and configure them accordingly.

The Protocol Confusion: A team was troubleshooting a network issue and couldn't figure out why packets weren't reaching the destination. They were looking at Layer 7 (application) protocols, but the issue was at Layer 2 (data link)—the switch was misconfigured. The fix? Understand which layer each component operates at, and troubleshoot systematically through the layers.

What Interviewers Are Really Testing

They want to hear you talk about the OSI model as a troubleshooting tool, not just theory. Junior engineers say "OSI has 7 layers." Senior engineers say "the OSI model helps you debug network issues by narrowing down which layer has the problem. Understanding which layer devices and protocols operate at helps you configure and troubleshoot systems."

When they ask "At which OSI layer does X operate?", they're testing:

  • Do you understand what each layer does?

  • Can you identify which layer devices and protocols operate at?

  • Can you use the OSI model to troubleshoot network issues?

  • TCP vs UDP - TCP and UDP operate at Layer 4 (Transport), understanding these protocols demonstrates OSI layer concepts

  • Three-Way Handshake (TCP) - TCP connection establishment at Layer 4 illustrates how layers interact

  • IP Addressing (IPv4/IPv6) - IP operates at Layer 3 (Network), understanding addressing demonstrates network layer functionality

  • Load Balancers (L4 vs L7) - Load balancers operate at different OSI layers, understanding the model helps choose the right type

  • HTTP/1 vs HTTP/2 vs HTTP/3 - HTTP operates at Layer 7 (Application), understanding the application layer in practice

  • OSI model divides networking into 7 layers for standardization

  • Encapsulation: Each layer adds header, wraps data from layer above

  • Decapsulation: Each layer removes header, passes to layer above

  • Layer functions: Application (user interface), Transport (end-to-end), Network (routing), Data Link (framing), Physical (bits)

  • Troubleshooting: Identify which layer has the problem

  • Protocol mapping: Understand which protocols operate at which layers

  • TCP/IP vs OSI: TCP/IP has 4 layers, OSI has 7 (both useful for different purposes)

How InterviewCrafted Will Teach This

We'll teach this through production failures, not theory. Instead of memorizing "OSI has 7 layers," you'll learn through scenarios like "why did we spend hours debugging the wrong layer?"

You'll see how the OSI model helps you troubleshoot network issues and understand how protocols work together. When an interviewer asks "at which layer does X operate?", you'll think about the OSI model as a practical tool—not just theory.

Key Takeaways

OSI model divides networking into 7 layers for standardization

Encapsulation: Each layer adds header, wraps data from layer above

Decapsulation: Each layer removes header, passes to layer above

Layer functions: Application (user interface), Transport (end-to-end), Network (routing), Data Link (framing), Physical (bits)

Troubleshooting: Identify which layer has the problem

Protocol mapping: Understand which protocols operate at which layers

TCP/IP vs OSI: TCP/IP has 4 layers, OSI has 7 (both useful for different purposes)


About the author

InterviewCrafted helps you master system design with patience. We believe in curiosity-led engineering, reflective writing, and designing systems that make future changes feel calm.