Loading W Code...
Open Systems Interconnection - 7 Layer Model
Remember: "Please Do Not Throw Sausage Pizza Away" (Physical, Data Link, Network, Transport, Session, Presentation, Application) - from bottom to top!
Data Unit: Data
Protocols
HTTP, HTTPS, FTP, SMTP, DNS, DHCP, Telnet, SSH
Devices
Gateways, Firewalls
The Application Layer is the topmost layer and closest to the end user. It provides network services directly to applications.
Key Functions:
Real-world Example: When you open a web browser and visit a website, you're using HTTP/HTTPS protocols at the Application Layer.
// HTTP Request Example
GET /index.html HTTP/1.1
Host: www.example.com
User-Agent: Mozilla/5.0
Accept: text/html
// HTTP Response
HTTP/1.1 200 OK
Content-Type: text/html
Content-Length: 1234
<html>...</html>Data Unit: Data
Protocols
SSL/TLS, JPEG, MPEG, GIF, ASCII, EBCDIC
Devices
Gateway
The Presentation Layer acts as a translator between the network and application. It handles data formatting, encryption, and compression.
Key Functions:
Real-world Example: When you see the "🔒" lock icon in your browser, SSL/TLS at the Presentation Layer is encrypting your data.
// SSL/TLS Handshake Steps
1. Client Hello: Supported cipher suites
2. Server Hello: Selected cipher suite
3. Server Certificate: Public key
4. Key Exchange: Pre-master secret
5. Change Cipher Spec: Switch to encrypted
// Example: Data Encryption
Original: "Password123"
Encrypted: "8f14e45f ceea167a 3b3b8b70 5a5d8e8d"
// Data Compression
Original: 1000 bytes
Compressed: 300 bytes (70% reduction)Data Unit: Data
Protocols
NetBIOS, PPTP, RPC, SQL, NFS
Devices
Gateway
The Session Layer establishes, manages, and terminates sessions between applications. It acts like a "dialog controller."
Key Functions:
Session Modes:
// Session Example: Video Call
1. Session Establishment
User A ──[Connect Request]──> User B
User A <──[Connect Accept]─── User B
2. Data Transfer (Full Duplex)
User A ←──[Video/Audio]───→ User B
3. Checkpoints (Recovery Points)
Checkpoint 1 → Checkpoint 2 → Checkpoint 3
4. Session Termination
User A ──[Disconnect]──> User BData Unit: Segment (TCP) / Datagram (UDP)
Protocols
TCP, UDP, SCTP, DCCP
Devices
Gateway, Firewall
The Transport Layer provides end-to-end communication between processes. It's responsible for reliable data transfer.
Key Functions:
TCP vs UDP:
| Feature | TCP | UDP |
|---|---|---|
| Connection | Connection-oriented | Connectionless |
| Reliability | Reliable (ACK) | Unreliable |
| Speed | Slower | Faster |
| Use Case | Web, Email | Gaming, Streaming |
// TCP 3-Way Handshake
Client ──[SYN]────────> Server // Step 1
Client <──[SYN-ACK]──── Server // Step 2
Client ──[ACK]────────> Server // Step 3
// Connection Established!
// TCP Header (Important Fields)
┌─────────────────────────────────┐
│ Source Port │ Destination Port │
├─────────────────────────────────┤
│ Sequence Number │
├─────────────────────────────────┤
│ Acknowledgment Number │
├─────────────────────────────────┤
│ Flags: SYN ACK FIN RST PSH URG │
└─────────────────────────────────┘
// Port Numbers
HTTP: 80 HTTPS: 443
FTP: 21 SSH: 22
SMTP: 25 DNS: 53Data Unit: Packet
Protocols
IP, ICMP, IGMP, IPsec, ARP, RARP
Devices
Router, Layer 3 Switch
The Network Layer handles logical addressing and routing. It determines the best path for data to travel across networks.
Key Functions:
Important Concepts:
// IPv4 Header Structure
┌───────────────────────────────────────┐
│ Version │ IHL │ ToS │ Total Length │
├───────────────────────────────────────┤
│ Identification │ Flags │ Frag Offset │
├───────────────────────────────────────┤
│ TTL │ Protocol │ Header Checksum │
├───────────────────────────────────────┤
│ Source IP Address │
├───────────────────────────────────────┤
│ Destination IP Address │
└───────────────────────────────────────┘
// Routing Example
Source: 192.168.1.10
Destination: 10.0.0.5
Path: Router1 → Router2 → Router3
Hops: 3 (TTL decremented at each hop)
// ICMP: Ping Command
$ ping google.com
Reply from 142.250.190.14: bytes=32 time=15ms TTL=57Data Unit: Frame
Protocols
Ethernet, PPP, HDLC, Frame Relay, ATM
Devices
Switch, Bridge, NIC
The Data Link Layer provides node-to-node data transfer and handles physical addressing (MAC addresses).
Two Sub-layers:
Key Functions:
// Ethernet Frame Structure
┌─────────────────────────────────────────────┐
│ Preamble │ SFD │ Dest MAC │ Src MAC │ Type │
├─────────────────────────────────────────────┤
│ Data (46-1500 bytes) │
├─────────────────────────────────────────────┤
│ FCS (CRC) │
└─────────────────────────────────────────────┘
// MAC Address Example
AA:BB:CC:DD:EE:FF
│ │ │ │ │ └─ Device ID (OUI)
└──┴──┴──────────── Manufacturer ID
// CSMA/CD (Carrier Sense Multiple Access / Collision Detection)
1. Listen before transmitting
2. If channel busy, wait
3. If collision detected, stop and retry
4. Random backoff before retransmittingData Unit: Bits
Protocols
Ethernet Physical, USB, Bluetooth, RS-232
Devices
Hub, Repeater, Cables, NIC
The Physical Layer is the lowest layer, dealing with actual physical transmission of raw bits over a medium.
Key Functions:
Transmission Media:
// Physical Layer Specifications
┌───────────────────────────────────────┐
│ Medium │ Speed │ Distance │
├───────────────────────────────────────┤
│ Cat5e │ 1 Gbps │ 100m │
│ Cat6 │ 10 Gbps │ 55m │
│ Fiber Optic │ 100+ Gbps │ 100+ km │
│ Coaxial │ 10 Mbps │ 500m │
└───────────────────────────────────────┘
// Encoding Schemes
NRZ (Non-Return to Zero)
Manchester Encoding
4B/5B Encoding
// Signal Types
Digital: Discrete values (0, 1)
Analog: Continuous waveform
// Bit Rate vs Baud Rate
Bit Rate = Baud Rate × Bits per Signal
Example: 1000 baud × 4 bits = 4000 bpsKnow the mnemonic: "Please Do Not Throw Sausage Pizza Away"
Understand data encapsulation: Data → Segment → Packet → Frame → Bits
Know which devices operate at which layer (Router=Layer 3, Switch=Layer 2)
Be ready to compare OSI vs TCP/IP model (7 layers vs 4 layers)