The OSI Model: complete guide (free)
by @zeroexploitable · security, explained in 60 seconds
Yaad rakhne ka trick (top to bottom): All People Seem To Need Data Processing
7 layers at a glance
| Layer | Name | Kaam (job) | PDU | Protocols | Devices |
|---|---|---|---|---|---|
| L7 | Application | Where apps talk to the network | Data | HTTP/HTTPS, DNS, SMTP, FTP, SSH | Hosts, proxies, WAFs |
| L6 | Presentation | Formats, encrypts and compresses data | Data | TLS/SSL encryption, JPEG, ASCII, UTF-8 | Hosts |
| L5 | Session | Opens, keeps and closes conversations | Data | NetBIOS, RPC, session tokens | Hosts |
| L4 | Transport | Splits data, numbers it, delivers it reliably | Segment | TCP, UDP, ports | Firewalls, load balancers |
| L3 | Network | Addresses and routes packets between networks | Packet | IPv4, IPv6, ICMP | Routers |
| L2 | Data Link | Moves frames between devices on the same network | Frame | Ethernet, Wi-Fi (802.11), ARP, MAC addresses | Switches, bridges |
| L1 | Physical | Sends raw bits as signals | Bits | Copper, fibre, radio (Wi-Fi), USB | Cables, hubs, repeaters |
India Post analogy
- The letter you write → L7 Application
- Packing and sealing it → L6 Presentation
- Keeping the conversation going → L5 Session
- Numbered boxes → L4 Transport
- The PIN code on the label → L3 Network
- Hub-to-hub courier tracking ID → L2 Data Link
- Roads, rails and trucks → L1 Physical
Encapsulation (send dabate hi)
- Data (L7-L5) → Segment = TCP header + data (L4) → Packet = IP header + segment (L3) → Frame = MAC header + packet + FCS (L2) → Bits on the wire (L1)
- Receiver ulte order mein headers hatata hai (de-encapsulation).
Attacks and defences per layer
| Layer | Attack | Defence |
|---|---|---|
| L7 Application | Phishing, SQL injection | Input validation, MFA, WAF |
| L6 Presentation | SSL stripping | HTTPS everywhere, HSTS |
| L5 Session | Session hijacking | Secure cookies, short session timeouts |
| L4 Transport | SYN flood | SYN cookies, rate limiting |
| L3 Network | IP spoofing | Ingress filtering, ACLs |
| L2 Data Link | ARP spoofing | Dynamic ARP inspection, port security |
| L1 Physical | Cable tapping, rogue devices | Locked network rooms, port control |
OSI vs TCP/IP
| TCP/IP | OSI |
|---|---|
| Application | L7, L6, L5 |
| Transport | L4 |
| Internet | L3 |
| Link | L2, L1 |
Note: OSI (ISO/IEC 7498-1) is a conceptual model. Real networks run TCP/IP; in practice TLS runs above TCP even though textbooks place encryption at L6.
Ports to know
SSH 22/TCP · DNS 53/UDP+TCP · HTTP 80/TCP · HTTPS 443/TCP
10 interview questions
- PDU at each layer? Data (L7-L5), Segment (L4), Packet (L3), Frame (L2), Bits (L1).
- Switch vs router? Switch: L2, forwards by MAC. Router: L3, forwards by IP.
- TCP vs UDP? TCP: connection-oriented, reliable, ordered. UDP: connectionless, lighter, no delivery guarantee.
- TCP 3-way handshake? SYN, SYN-ACK, ACK.
- SYN flood? Many SYNs, handshake never completed, half-open table fills. Defence: SYN cookies, rate limiting.
- ARP spoofing? Forged ARP replies map attacker MAC to another IP (MITRE ATT&CK T1557.002). Defence: Dynamic ARP Inspection.
- Which layer are ports? Transport (L4).
- Where do firewalls work? Packet filters L3/L4; next-gen firewalls and WAFs up to L7.
- OSI vs TCP/IP? TCP/IP has 4 layers: Application (5-7), Transport (4), Internet (3), Link (1-2).
- Why troubleshoot bottom-up? Lower layers fail cheaply and break everything above: cable, link, IP, then app.
Sources
ISO/IEC 7498-1 · Cloudflare Learning: What is the OSI model? · Codecademy OSI guide · Cloudflare: SYN flood · MITRE ATT&CK T1557.002, T1566
OSI Daily: roz ek layer. Follow @zeroexploitable on Instagram: https://www.instagram.com/zeroexploitable/