OSI Model

Beginner
Fundamentals

The OSI model is a 7-layer conceptual framework that standardises how different network protocols communicate, from physical bit transmission to application-level data exchange.

Overview

The Open Systems Interconnection (OSI) model, defined by ISO in 1984, divides network communication into 7 discrete layers: Physical, Data Link, Network, Transport, Session, Presentation, and Application. Each layer has a specific responsibility and communicates only with the layer directly above and below it. When data is sent, it travels down from Layer 7 to Layer 1 — each layer adding its own header (encapsulation). When received, it travels back up — each layer stripping its header (decapsulation). The OSI model is a theoretical reference; in practice, the TCP/IP model is used. But OSI is the universal language for discussing networking — interviewers expect you to map protocols and troubleshoot issues using OSI layers.

The 7 Layers

Each layer serves a distinct purpose. Layers 1–4 are transport-oriented; Layers 5–7 are application-oriented. A common mnemonic: "Please Do Not Throw Sausage Pizza Away" (Physical, Data Link, Network, Transport, Session, Presentation, Application).

OSI layers and Java socket placement
// OSI Layers — top to bottom
// ┌─────────────────────────────────────────────────────────────────────┐
// │ Layer 7 — Application   │ HTTP, HTTPS, FTP, SMTP, DNS, WebSocket   │
// │ Layer 6 — Presentation  │ TLS/SSL, JPEG, MPEG, ASCII encoding      │
// │ Layer 5 — Session       │ NetBIOS, RPC, session establishment      │
// │ Layer 4 — Transport     │ TCP, UDP — ports, reliability, flow ctrl │
// │ Layer 3 — Network       │ IP, ICMP, ARP, routing                   │
// │ Layer 2 — Data Link     │ Ethernet, MAC, switches, frames          │
// │ Layer 1 — Physical      │ Cables, fibre, Wi-Fi, bits               │
// └─────────────────────────────────────────────────────────────────────┘

// Java socket sits at Layer 4/5 boundary:
ServerSocket server = new ServerSocket(8080);   // Transport layer (TCP port)
Socket client = server.accept();               // Session layer (connection)
InputStream in = client.getInputStream();      // Layer 5–7 data exchange

Encapsulation & Decapsulation

As data moves down the stack on the sender, each layer wraps it with its own header (and sometimes trailer). The receiver strips headers in reverse order. Each layer only sees its own header — Layer 3 does not know about Layer 7 content.

Encapsulation walkthrough
// Encapsulation (sender, top → bottom):
// Application data:    [ HTTP Request ]
// Layer 4 (Transport): [ TCP Header | HTTP Request ]
// Layer 3 (Network):   [ IP Header  | TCP Header | HTTP Request ]
// Layer 2 (Data Link): [ ETH Header | IP Header  | TCP Header | HTTP Request | ETH Trailer ]
// Layer 1 (Physical):  101010111001...  (bits over wire)

// Decapsulation (receiver, bottom → top):
// Layer 1: receives bits, assembles frame
// Layer 2: strips Ethernet header, passes IP packet up
// Layer 3: strips IP header, passes TCP segment up
// Layer 4: strips TCP header, reassembles stream, passes to application
// Layer 7: application reads HTTP request

Practical Layer Mapping

Real protocols map to specific OSI layers. When debugging, knowing which layer a problem is at narrows down the cause — a DNS failure is Layer 7; an IP routing issue is Layer 3; a broken cable is Layer 1.

Protocol-to-layer mapping and troubleshooting
// Protocol → Layer mapping (exam-critical):
// HTTP, HTTPS, FTP, SMTP, DNS, DHCP, WebSocket → Layer 7 (Application)
// TLS/SSL encryption/decryption              → Layer 6 (Presentation)
// TCP connection management                  → Layer 5 (Session) / Layer 4
// TCP, UDP, SCTP                             → Layer 4 (Transport)
// IP (IPv4, IPv6), ICMP, OSPF, BGP          → Layer 3 (Network)
// Ethernet, Wi-Fi (802.11), MAC, ARP         → Layer 2 (Data Link)
// Cables, optical fibre, radio signals       → Layer 1 (Physical)

// Troubleshooting using layers:
// Can't ping?        → Check Layer 1 (cable) or Layer 3 (IP/route)
// DNS not resolving? → Layer 7 issue (DNS server, config)
// TCP connection refused? → Layer 4 (wrong port, firewall)
// TLS handshake fails?    → Layer 6 (certificate, cipher mismatch)

Key Points to Remember

  • 1OSI has 7 layers: Physical (1), Data Link (2), Network (3), Transport (4), Session (5), Presentation (6), Application (7).
  • 2Each layer adds its own header during encapsulation and strips it during decapsulation.
  • 3The OSI model is theoretical; TCP/IP (4 layers) is what is actually implemented.
  • 4Routers operate at Layer 3; switches at Layer 2; hubs at Layer 1.
  • 5TLS operates at Layer 6 (Presentation) — it encrypts before TCP sends data.
  • 6Knowing which layer a protocol belongs to is critical for network troubleshooting.

Interview Questions

Sign in to ask Aria
1

What are the 7 layers of the OSI model and what does each do?

EasyTCS
2

At which OSI layer does TLS/SSL operate?

EasyInfosys
3

What is the difference between a router and a switch in terms of OSI layers?

EasyWipro
4

Explain encapsulation and decapsulation in the OSI model.

MediumCapgemini
5

A client can ping the server but cannot establish a TCP connection. Which layer is the issue at?

MediumAmazon

Ask Aria about OSI Model

Your personal AI tutor — ask anything about this concept

Revision Status

Personal Notes

Sign in to save personal notes for this topic.

Discussion

Sign in to join the discussion.

Loading discussion…