Network models help us understand how communication happens. They break down complex network processes into layers, where each layer has specific responsibilities.
The OSI Model (7 Layers)
The OSI (Open Systems Interconnection) model is a conceptual framework standardized by ISO. It divides networking into 7 layers.
Memory aid: Please Do Not Throw Sausage Pizza Away
| Layer | Name | Purpose | Examples |
|---|---|---|---|
| 7 | Application | User applications, services | HTTP, HTTPS, SSH, DNS, FTP |
| 6 | Presentation | Data formatting, encryption, compression | SSL/TLS, JPEG, MPEG |
| 5 | Session | Connection management, dialogues | NetBIOS, RPC |
| 4 | Transport | End-to-end communication, reliability | TCP, UDP, SCTP |
| 3 | Network | Routing, logical addressing | IP (IPv4, IPv6), ICMP |
| 2 | Data Link | Frame delivery, physical addressing | Ethernet, PPP, MAC addresses |
| 1 | Physical | Cables, signals, electrical | Fiber optic, Ethernet cable, WiFi |
OSI Layers Explained
Layer 7: Application Layer
- Closest to end users
- Where applications operate
- HTTP (web), SMTP (email), SSH (remote access)
- User interacts here
Layer 6: Presentation Layer
- Data translation and formatting
- Encryption/decryption (SSL/TLS)
- Compression/decompression
- Example: Browser receives encrypted HTTPS data → decrypts and decodes
Layer 5: Session Layer
- Manages conversations between devices
- Starts, maintains, ends sessions
- Authentication and authorization
- Example: Log into remote server, session established
Layer 4: Transport Layer
- End-to-end communication between processes
- TCP (reliable) or UDP (fast)
- Port numbers
- Example: Web browser connects to port 80 on server
Layer 3: Network Layer
- Routing between networks
- IP addresses (logical addressing)
- Routers operate here
- Example: Packet travels from 192.168.1.100 to 10.0.0.50
Layer 2: Data Link Layer
- Delivers frames locally (between directly connected devices)
- MAC addresses (physical addressing)
- Switches operate here
- Example: PC sends to printer on same network using MAC address
Layer 1: Physical Layer
- Actual wires, cables, radio signals
- Voltages, frequencies, connector types
- No software, pure hardware
- Example: Ethernet cable, WiFi transmitter
Data Encapsulation (PDU - Protocol Data Unit)
As data moves down the layers, each layer adds its own header:
Layer 7 (Application): [HTTP Request Data]
↓ Add HTTP header
Layer 6 (Presentation): [HTTP Header | Data]
↓ Add TLS header
Layer 5 (Session): [Session Header | HTTP | Data]
↓
Layer 4 (Transport): [TCP Header | Session | HTTP | Data]
↓
Layer 3 (Network): [IP Header | TCP | Session | HTTP | Data]
↓
Layer 2 (Data Link): [Ethernet Header | IP | TCP | Session | HTTP | Data | Trailer]
↓
Layer 1 (Physical): [Electrical Signals / Radio waves]
Each layer: Header + Payload from higher layer = its own "packet"
Names: Segment (L4), Packet (L3), Frame (L2)
TCP/IP Model (4 Layers)
The TCP/IP Model (also called Internet model) is more practical and widely used than OSI. It has 4 layers.
| Layer | OSI Equivalent | Purpose | Examples |
|---|---|---|---|
| 4 | Application | User applications and services | HTTP, HTTPS, SSH, DNS, FTP, SMTP |
| 3 | Transport | Process-to-process communication | TCP, UDP |
| 2 | Internet | Routing and logical addressing | IP, ICMP, ARP |
| 1 | Link | Physical transmission | Ethernet, WiFi, PPP |
TCP/IP Layers in Detail
Application Layer (Layer 4)
- Combines OSI layers 5, 6, 7
- All user-facing applications
- HTTP/HTTPS, SSH, DNS, FTP, SMTP, Telnet
- Sockets API for applications
- Example: Web browser, email client, SSH client
Transport Layer (Layer 3)
- TCP (Transmission Control Protocol) — reliable, ordered
- UDP (User Datagram Protocol) — fast, unreliable
- Port numbers (source and destination)
- Flow control, error checking
- Example: Port 80 for HTTP, Port 443 for HTTPS
Internet Layer (Layer 2)
- IP routing between networks
- IPv4 and IPv6 addresses
- ICMP (ping, traceroute)
- ARP (address resolution)
- Example: Routing packet from 192.168.1.100 to 10.0.0.50
Link Layer (Layer 1)
- Ethernet, WiFi, PPP
- MAC addresses
- Physical and data link combined
- Example: Ethernet cable transports frames
OSI vs TCP/IP — When to Use Each?
OSI Model
- Teaching/reference framework
- Detailed protocol analysis
- Academic discussions
- "Which layer is this responsible for?"
TCP/IP Model
- Practical networking
- Most internet services
- What you use day-to-day
- "How does the stack work?"
Cross-Layer Communication Example
User wants to visit google.com
Layer 7 (Application):
─ Browser application
─ Types: google.com
─ Action: Make HTTP request
Layer 6 (Presentation):
─ Format the request
─ Potentially encrypt (HTTPS)
Layer 5 (Session):
─ Establish session with google.com
─ Remember session state
Layer 4 (Transport):
─ TCP connection to 142.251.41.14:443
─ Three-way handshake
─ Reliable delivery guaranteed
Layer 3 (Network):
─ Check: "How do I reach 142.251.41.14?"
─ Consult routing table
─ Forward to router: 192.168.1.1
Layer 2 (Data Link):
─ "What's the MAC of router 192.168.1.1?"
─ ARP query for MAC address
─ Send frame to router's MAC
Layer 1 (Physical):
─ Electrical signals through Ethernet cable
─ Bits transmitted as voltages
On the return:
Layer 1 (Physical):
─ Signals arrive as electrical pulses
Layer 2 (Data Link):
─ Extract frame
─ Check destination MAC (my MAC)
─ Extract IP packet
Layer 3 (Network):
─ Check destination IP (my IP)
─ Extract TCP segment
Layer 4 (Transport):
─ Check destination port (443)
─ Reassemble TCP segments if fragmented
─ Pass to browser application
Layer 5-7 (Session/Presentation/Application):
─ Browser recognizes HTTP response
─ Decrypts HTTPS data
─ Renders HTML page
Protocol Layering Examples
Web Browsing (HTTPS)
Application: HTTP request/response
Presentation: TLS encryption (SSL/TLS)
Session: HTTP session management
Transport: TCP port 443
Internet: IP routing to web server
Link: Ethernet frames
Physical: Fiber optic cable
VoIP Call
Application: SIP (Session Initiation Protocol)
Presentation: Voice codec (compression)
Session: Call session establishment
Transport: UDP port 5060 (SIP), RTP (audio)
Internet: IP routing
Link: Ethernet or WiFi
Physical: Network cables/radio
Application: SMTP (send), POP3/IMAP (receive)
Presentation: TLS encryption
Session: SMTP/POP3 session
Transport: TCP port 25, 110, 143, 587
Internet: IP routing to mail server
Link: Ethernet
Physical: ISP connection
Key Concepts for DevOps
Understanding layers helps troubleshoot:
Problem: "Users can't access server"
Check Layer 4 (Transport):
Is port 80 listening? netstat -tuln
Is firewall allowing? iptables -L
Check Layer 3 (Network):
Can you ping server? ping 10.0.0.50
Is routing correct? traceroute 10.0.0.50
Check Layer 2 (Data Link):
Is MAC address resolving? arp -a
Check Layer 1 (Physical):
Is cable plugged in? Check physical connection
Systematic approach: Start high, work down to physical
Tools by Layer
| Layer | Tools |
|---|---|
| 7 | curl, wget, telnet, ssh |
| 6 | openssl, gpg |
| 5 | netstat, lsof |
| 4 | netstat, ss, tcpdump |
| 3 | ping, traceroute, mtr, ip route |
| 2 | arp, mac-lookup, tcpdump |
| 1 | ethtool, mii-tool, ifconfig |
Summary Table: OSI vs TCP/IP
| OSI Layer | TCP/IP Layer | Key Responsibility | Protocols |
|---|---|---|---|
| 7 | 4 | Applications | HTTP, SSH, DNS |
| 6 | 4 | Encryption | TLS, SSL |
| 5 | 4 | Sessions | NetBIOS |
| 4 | 3 | Reliability | TCP, UDP |
| 3 | 2 | Routing | IP, ICMP |
| 2 | 1 | Addressing | Ethernet, MAC |
| 1 | 1 | Transmission | Fiber, Cable |
Key Takeaways
- OSI = 7 layers: detailed reference model
- TCP/IP = 4 layers: practical Internet model
- Encapsulation = each layer adds headers
- Headers removed as data moves up on receiver
- Layer 3+ = routed on Internet
- Layer 2 = local delivery (switched)
- Layer 1 = physical transmission
- Know the layers to troubleshoot effectively
- Most Internet services are TCP/IP (Layer 4 and up focused)