OSI Model vs TCP/IP Model: All 7 Layers, Protocols and What Happens When You Open a Website
Each layer’s job and protocols, how the two models map, and the request journey interviewers ask you to explain.
Coding problems with instant test-case feedback
Write Python, C++, C or JavaScript in your browser and see which hidden tests pass.
Networking is built in layers. Each layer solves one problem and relies on the layer below it. The OSI model has seven layers and is mostly a teaching model; the TCP/IP model has four and describes how the internet actually works. You are expected to know both and how they line up.
1. The seven OSI layers#
From top (closest to the user) to bottom (the wire):
| # | Layer | Job | Examples | Data unit |
|---|---|---|---|---|
| 7 | Application | Network services for applications | HTTP, DNS, SMTP, FTP | Data |
| 6 | Presentation | Encoding, encryption, compression | TLS, JPEG, UTF-8 | Data |
| 5 | Session | Open, manage and close sessions | RPC, session checkpoints | Data |
| 4 | Transport | End-to-end delivery between processes (ports) | TCP, UDP | Segment / datagram |
| 3 | Network | Logical addressing and routing between networks | IP, ICMP, routers | Packet |
| 2 | Data link | Delivery on one link, MAC addresses, error detection | Ethernet, Wi-Fi, switches, ARP | Frame |
| 1 | Physical | Bits as signals on a medium | Cables, radio, hubs | Bit |
"Please Do Not Throw Sausage Pizza Away", from layer 1 up: Physical, Data link, Network, Transport, Session, Presentation, Application.
2. How OSI maps to TCP/IP#
The TCP/IP model merges OSI layers 5–7 into one Application layer and layers 1–2 into a Link (network access) layer.
| TCP/IP layer | OSI layers | Protocols |
|---|---|---|
| Application | 7, 6, 5 | HTTP, HTTPS, DNS, SMTP, SSH |
| Transport | 4 | TCP, UDP |
| Internet | 3 | IP (v4, v6), ICMP |
| Link | 2, 1 | Ethernet, Wi-Fi, ARP |
Practise placement aptitude on the real test pattern
TCS NQT, Infosys, Wipro, Accenture and Cognizant style mocks with section-wise analysis.
3. TCP vs UDP#
| TCP | UDP | |
|---|---|---|
| Connection | Connection-oriented (three-way handshake: SYN, SYN-ACK, ACK) | Connectionless |
| Reliability | Retransmits lost data, delivers in order | No guarantee of delivery or order |
| Flow and congestion control | Yes | No |
| Header size | 20–60 bytes | 8 bytes |
| Used for | Web pages, email, file transfer | DNS lookups, video calls, online games |
4. What happens when you type a URL and press Enter#
This is one of the most common networking interview questions. A good answer walks down the layers:
- DNS: the browser checks its cache, then asks a DNS resolver to turn the domain name into an IP address (usually over UDP port 53).
- TCP: the browser opens a TCP connection to that IP on port 443 with the three-way handshake.
- TLS: client and server agree on keys and the server proves its identity with a certificate, so the rest is encrypted.
- HTTP: the browser sends GET / with headers; the server responds with status 200 and the HTML.
- Below that, IP routes the packets hop by hop through routers, and on each link Ethernet or Wi-Fi delivers frames using MAC addresses found with ARP.
- Rendering: the browser parses the HTML, requests CSS, JavaScript and images (often over the same connection) and paints the page.
Mentioning DNS caching, the TLS handshake, or that HTTP/3 runs over QUIC on UDP shows you understand the stack rather than a memorised list.
Test Your Concept Mastery
Verify your retention on: OSI Model vs TCP/IP Model: All 7 Layers, Protocols and What Happens When You Open a Website
At which OSI layer do routers mainly operate?
Which protocol does a typical DNS lookup use?
Ready for a full proctored assessment?
Take a free aptitude mock on a real company pattern, with a worked solution for every question.