OSI Model¶
The OSI model has 7 layers that describe how data flows through a network. From top to bottom: Application (HTTP), Presentation (SSL/TLS), Session, Transport (TCP/UDP), Network (IP), Data Link (Ethernet), Physical (cables). In practice, the TCP/IP model (4 layers) is more commonly used. Data is encapsulated going down (headers added) and decapsulated going up.
Key Concepts¶
Deep Dive: The 7 Layers
| Layer | Name | Protocol | Unit | Purpose |
|---|---|---|---|---|
| 7 | Application | HTTP, DNS, FTP | Data | User-facing protocols |
| 6 | Presentation | SSL/TLS, JPEG | Data | Encryption, compression |
| 5 | Session | Sockets | Data | Session management |
| 4 | Transport | TCP, UDP | Segment | Reliable delivery, ports |
| 3 | Network | IP, ICMP | Packet | Routing, IP addressing |
| 2 | Data Link | Ethernet, MAC | Frame | Physical addressing |
| 1 | Physical | Cables, WiFi | Bits | Raw bit transmission |
Mnemonic (top to bottom): All People Seem To Need Data Processing
Deep Dive: TCP/IP Model (Practical)
| TCP/IP Layer | OSI Layers | Protocol |
|---|---|---|
| Application | 5, 6, 7 | HTTP, DNS, SMTP |
| Transport | 4 | TCP, UDP |
| Internet | 3 | IP, ICMP |
| Network Access | 1, 2 | Ethernet, WiFi |
Deep Dive: What Happens When You Type a URL
1. Browser checks cache for DNS record
2. DNS lookup: domain → IP address
3. TCP 3-way handshake (SYN → SYN-ACK → ACK)
4. TLS handshake (if HTTPS)
5. HTTP request sent to server
6. Server processes request, sends response
7. Browser renders HTML, fetches CSS/JS/images
8. TCP connection closed (or kept alive)
Common Interview Questions
- What are the layers of the OSI model?
- What happens when you type a URL in the browser?
- At which layer does a router operate? Switch? Firewall?
- What is the difference between OSI and TCP/IP models?