Appearance
OSI Model (Open Systems Interconnection)
A conceptual framework that standardizes how different network systems communicate. It breaks communication into 7 layers, each with a specific job.
The 7 Layers (Top → Bottom)
| # | Layer | What it does | Examples |
|---|---|---|---|
| 7 | Application | Interface for the end user/app | HTTP, FTP, DNS, SMTP |
| 6 | Presentation | Translation, encryption, compression | SSL/TLS, JPEG, ASCII |
| 5 | Session | Opens, manages, closes sessions | NetBIOS, RPC |
| 4 | Transport | End-to-end delivery, reliability | TCP, UDP |
| 3 | Network | Logical addressing, routing | IP, ICMP, routers |
| 2 | Data Link | Physical addressing, error detection | MAC, Ethernet, switches |
| 1 | Physical | Raw bits over the wire | Cables, hubs, signals |
Layer-by-Layer Detail
Layer 7 – Application
- Closest to the user. Protocols: HTTP, DNS, FTP.
- It is NOT the app itself (like Chrome) — it is the protocol the app uses.
Layer 6 – Presentation
- Translates data into a format the app can understand.
- Handles encryption (TLS), compression, and encoding (UTF-8, ASCII).
- Often considered the least discussed layer in interviews.
Layer 5 – Session
- Manages sessions — establishing, maintaining, and terminating connections.
- Think of it as managing a "conversation" between two devices.
Layer 4 – Transport ★ (very interview-heavy)
- Responsible for end-to-end communication.
- TCP → reliable, ordered, connection-oriented (uses handshakes).
- UDP → fast, connectionless, no guarantee of delivery.
- Introduces ports (e.g. HTTP = 80, HTTPS = 443).
- Handles segmentation — breaking large data into smaller chunks.
Layer 3 – Network ★
- Deals with logical addressing (IP addresses) and routing.
- Routers operate here.
- Decides the best path for data across networks.
Layer 2 – Data Link ★
- Deals with physical (MAC) addresses.
- Responsible for node-to-node delivery within the same network.
- Switches operate here.
- Detects (sometimes corrects) errors from Layer 1.
Layer 1 – Physical
- Raw transmission of bits (0s and 1s) over a physical medium.
- Cables, fiber optics, radio signals, hubs.
How Data Flows — Encapsulation & Decapsulation
When you send data, each layer wraps it with its own header (called encapsulation). On the receiving end, each layer unwraps it (decapsulation).
Sender (goes DOWN — Encapsulation):
Layer 7 - Application → [Data]
Layer 6 - Presentation → [Data]
Layer 5 - Session → [Data]
Layer 4 - Transport → [L4 Header | Data] → Segment
Layer 3 - Network → [L3 | L4 | Data] → Packet
Layer 2 - Data Link → [L2 | L3 | L4 | Data] → Frame
Layer 1 - Physical → 101010... → Bits on wireReceiver (goes UP — Decapsulation):
Layer 1 - Physical → receives raw bits
Layer 2 - Data Link → strips L2 header, checks MAC
Layer 3 - Network → strips L3 header, checks IP
Layer 4 - Transport → strips L4, checks port, reassembles
Layer 5 - Session → manages session
Layer 6 - Presentation → decrypts/decompresses
Layer 7 - Application → hands data to the app ✓Devices in the Middle
| Device | Layers it processes |
|---|---|
| Hub | L1 only — just forwards bits |
| Switch | L1 + L2 — reads MAC, forwards frame |
| Router | L1 + L2 + L3 — reads IP, routes packet |
| Firewall / Load Balancer | Up to L4 or L7 depending on type |
Router example:
Incoming: Bits → Frame → Packet → [reads IP] → Packet → Frame → Bits : Outgoing
UP to L3 ↑ DOWN from L3 ↓Mental Model
- Sending = going DOWN (wrapping/encapsulating)
- Receiving = going UP (unwrapping/decapsulating)
- Middle devices = go up only as far as they need, then back down
Common Interview Questions
Q: Why does the OSI model matter? It gives a common language to troubleshoot and design networks. When something breaks, you can isolate which layer the problem is at.
Q: A website isn't loading — which layer do you check? Go bottom-up: Is the cable connected? (L1) → Is there a network? (L2/L3) → Can you ping? (L3) → Can you reach the port? (L4) → Is the app responding? (L7)
Mnemonic (top to bottom): All People Seem To Need Data Processing