system design

OSI Model Explained: 7 Layers of Networking

Understand the OSI model's 7 layers with simple explanations. Learn how data moves through a network and why this matters for backend developers.

By Akash Sharma·5 min read
#system design
#networking
#osi model
#backend
#protocols
#infrastructure

When data travels from your browser to a server, it passes through seven distinct stages. The OSI model gives each stage a name and a job. Once you understand it, network debugging becomes a lot less mysterious.

Fair warning: the OSI model is a theoretical framework. Real-world networking uses TCP/IP, which collapses these 7 layers into 4. But OSI gives you the vocabulary to discuss networking problems precisely — and it shows up constantly in technical interviews.

The 7 Layers (Bottom to Top)

Think of data traveling from your computer to a server as going down the layers on your side, through the wire, then back up the layers on the server's side.

Layer 1: Physical

The actual hardware. Cables, fiber optics, radio waves, voltage. This layer converts bits (0s and 1s) into electrical signals, light pulses, or radio waves.

No intelligence here — just raw signal transmission.

Troubleshoot at this layer when: The cable is unplugged. The Wi-Fi is physically too far from the router. Network card failure.

Layer 2: Data Link

Layer 2 takes the raw signals from Layer 1 and packages them into frames for transmission between two directly connected devices.

This is where MAC addresses live. Every network card has a unique MAC address. Switches (not routers) operate at Layer 2.

Troubleshoot at this layer when: Two devices on the same network can't communicate. Switch misconfiguration.

Layer 3: Network

Layer 3 handles routing between networks. This is where IP addresses live. Routers operate at Layer 3.

When you send data to a server on the other side of the world, Layer 3 figures out the path — through multiple routers, across multiple networks.

Troubleshoot at this layer when: Packets aren't routing correctly. You can ping by IP but not by hostname (DNS issue). Subnet misconfiguration.

Layer 4: Transport

Layer 4 handles end-to-end communication between applications. This is where TCP and UDP live.

TCP adds reliability: ordering, retransmission, flow control. UDP is faster but unreliable.

Port numbers live at this layer. Port 80 = HTTP. Port 443 = HTTPS. Port 5432 = PostgreSQL.

Troubleshoot at this layer when: Connections time out. Port is blocked by firewall. "Connection refused" errors.

Layer 5: Session

Layer 5 manages sessions — opening, maintaining, and closing communication channels between applications.

In practice, most modern protocols (HTTP, gRPC) handle session management themselves rather than relying on a separate Layer 5.

Layer 6: Presentation

Layer 6 handles data formatting and encryption. It translates data between the format the application uses and the format the network uses.

SSL/TLS encryption happens here. JSON serialization could be considered Layer 6.

Troubleshoot at this layer when: SSL certificate errors. Data encoding/decoding issues.

Layer 7: Application

The layer you interact with as a developer. HTTP, DNS, SMTP, FTP — these are Layer 7 protocols.

This is where your web application, API, and browser live.

Troubleshoot at this layer when: 404 errors, 500 errors, authentication failures, API timeouts.

The Layers as a Table

LayerNameProtocol ExamplesWhat It Does
7ApplicationHTTP, DNS, FTP, SMTPUser-facing protocols
6PresentationSSL/TLS, JPEG, JSONData format & encryption
5SessionNetBIOS, RPCSession management
4TransportTCP, UDPEnd-to-end delivery, ports
3NetworkIP, ICMPRouting between networks
2Data LinkEthernet, Wi-Fi, ARPFrames between local devices
1PhysicalCables, fiber, radioRaw bit transmission

How It Works in Practice: You Load a Web Page

  1. Layer 7: Your browser creates an HTTP GET request for example.com
  2. Layer 6: The request gets encrypted with TLS (HTTPS)
  3. Layer 5: A session is established
  4. Layer 4: TCP wraps the data with source/destination ports (your port → port 443)
  5. Layer 3: IP adds your IP and the server's IP — router finds the path
  6. Layer 2: Ethernet frames carry the data hop-by-hop between routers
  7. Layer 1: Electrical signals travel down the cable

On the server side, this happens in reverse.

Why Developers Care About OSI

Debugging: When something breaks, OSI helps you localize the problem. "Can I ping the server?" (Layer 3). "Can I telnet to port 443?" (Layer 4). "Is HTTPS certificate valid?" (Layer 6).

Security: Understanding where attacks happen helps you defend against them. DDoS attacks target Layer 3–4. XSS targets Layer 7. SQL injection is Layer 7.

Protocol choice: Choosing between TCP and UDP is a Layer 4 decision. Choosing between HTTP and gRPC is a Layer 7 decision.

Interview conversations: System design interviews often involve discussing network protocol choices. OSI vocabulary makes you sound credible.

TCP/IP: The Real-World Version

Real networks use TCP/IP, which maps the 7 OSI layers into 4:

plaintext
TCP/IP Model:        OSI Equivalent:
Application     ←→   Layers 5, 6, 7
Transport       ←→   Layer 4
Internet        ←→   Layer 3
Network Access  ←→   Layers 1, 2

Same concepts, simpler structure. OSI is the theoretical model; TCP/IP is what's actually implemented.

Key Takeaways

  • OSI has 7 layers, each with a specific job in moving data across networks
  • Layers 1–4 handle the how of transmission; layers 5–7 handle the what of communication
  • Port numbers live at Layer 4 (Transport); IP addresses at Layer 3 (Network)
  • TCP and UDP are Transport layer (Layer 4) protocols
  • HTTP, DNS, and your application live at Layer 7 (Application)
  • TCP/IP collapses OSI's 7 layers into 4 — that's what networks actually use

Understanding where a problem lives in the stack makes debugging much faster.

Related reading: TCP, UDP, HTTP, gRPC Explained · DNS Explained

Enjoyed this article?

Get weekly insights on backend architecture, system design, and Go programming.