Computer Network 📂 Introduction to Computer Networks · 2 of 3 65 min read

OSI Model vs TCP/IP: All 7 Layers Explained

A visual, layer-by-layer breakdown of the OSI reference model (7 layers) and the TCP/IP model (4 layers) — what each layer does, how they compare, and why engineers debug in OSI numbers but ship in TCP/IP. Includes 9 animated SVG diagrams (TCP handshake, IP routing, encapsulation, and more), a full comparison table, and real 2024–2025 outage case studies from Facebook's BGP failure to the CrowdStrike meltdown.

Section 01

The Story That Explains Reference Models

The International Letter
You want to send a physical letter from Sirhind to Tokyo. You don't personally negotiate with cargo airlines, Japanese customs, or a Tokyo postman. You just write a note, put it in an envelope, address it, and drop it in a postbox.

Behind the scenes, a whole stack of services takes over. The local postman picks it up. The regional office bags it with 200 other letters headed east. An airline flies the sack. In Japan, someone unbags it. A local Tokyo postman delivers it. Each stage does one job, uses its own "language," and hands the letter to the next stage. You never see any of that — but if any layer fails, your letter never arrives.

That is exactly what the OSI and TCP/IP reference models describe for computer networks: how a WhatsApp message from your phone becomes electrical pulses on a wire, crosses oceans, and rebuilds itself on your friend's phone — layer by layer, no layer knowing what the others actually do.

Every network engineer, every hacker, and every backend developer thinks in layers. When something breaks, the first question is always: which layer failed? A slow website is a very different problem depending on whether the cable is loose (Layer 1), a router is misconfigured (Layer 3), or the website's own code has crashed (Layer 7). Reference models give us the shared vocabulary to answer that question fast.

🌐
Two Models, One Idea

The OSI model is the teaching model — 7 clean layers, published by ISO in 1984. The TCP/IP model is the working model — 4 (or 5) layers, built by engineers building the real internet. Every network on Earth today runs TCP/IP. But we still teach OSI, because its 7 layers give you the sharpest mental map for debugging.


Section 02

Why We Need a Reference Model

In the 1970s, every computer maker built its own proprietary networking stack. IBM machines could only talk to IBM machines. DEC machines could only talk to DEC. Sending a file from one to the other required an expensive gateway box — sometimes literally a room full of hardware translating one dialect to another.

The International Organization for Standardization (ISO) proposed a solution: break the whole problem of "moving data from one computer to another" into seven independent layers. Publish clear rules for what each layer must do. Then any vendor can build any layer, and if they follow the rules, all their hardware and software will interoperate. The result — the OSI Reference Model — didn't win the market, but it won the classroom: every textbook in the world still teaches it because its 7 layers are the cleanest way to think about networks.

🔑
Why Layering Is Genius

Each layer only talks to the layer above and the layer below. Change one layer (say, upgrade Wi-Fi from 802.11n to 802.11ax) and no other layer needs to know or change. This is called abstraction and it is the same principle that lets you drive any car without knowing how the engine works.


Section 03

The OSI Model — All Seven Layers

Read this stack from top to bottom for data being sent, or bottom to top for data being received. Every packet on every network makes both journeys.

Animated Diagram — The 7 OSI Layers with Data Flowing Down
7 — Application Layer 7 6 — Presentation Layer 6 5 — Session Layer 5 4 — Transport Layer 4 3 — Network Layer 3 2 — Data Link Layer 2 1 — Physical Layer 1 HTTP, DNS, SMTP TLS, JPEG, ASCII NetBIOS, RPC TCP, UDP IP, ICMP, BGP MAC, Ethernet, Wi-Fi Cables, radio, fibre ↓ Sending: data flows top to bottom ↓
A single data packet flows down through all 7 layers before being turned into electrical pulses on the wire. On the receiving computer, it climbs back up.
📚
Two Classic Mnemonics

Bottom-up (Physical → Application): Please Do Not Throw Sausage Pizza Away.
Top-down (Application → Physical): All People Seem To Need Data Processing.


Section 04

Layer 1 — Physical Layer

This is the layer of raw bits. It defines cables, connectors, voltages, radio frequencies, light pulses in fibre, and how a "1" or a "0" is physically represented. It says nothing about what the bits mean — it just moves them.

Animated Diagram — Bits Travelling on a Copper Wire
Cat-6 Ethernet cable 1 0 1 1 0 1 0 1 +5V = "1" 0V = "0" Digital signal moving along the wire
A high voltage means "1", a low voltage means "0". Layer 1 is that simple — and that unforgiving. A bent pin here breaks everything above.
🔌 What Layer 1 Actually Deals With
Medium
Copper (Cat-6, coaxial), fibre optic strands, radio waves (Wi-Fi, 4G, 5G), infrared, laser.
Signals
Voltage levels, light pulses, radio-wave amplitude and frequency.
Devices
Hubs, repeaters, cables, antennas, connectors (RJ-45, LC), transceivers.
Unit
The bit.
Failures look like
"No link light", "cable unplugged", "Wi-Fi shows disconnected". A hardware problem, not a software one.

Section 05

Layer 2 — Data Link Layer

Layer 2 groups those raw bits into frames and gives every network card a unique MAC address (Media Access Control) — like 48-bit fingerprints burned into hardware at the factory. It handles who-talks-when on a shared medium and detects transmission errors within a single LAN. Switches operate here.

Animated Diagram — Layer 2 Frame Between Two MAC Addresses
PC-A MAC: 00:1A:2B:3C:4D:5E Switch reads MAC tables PC-B MAC: 00:7F:6E:5D:4C:3B FRAME Frame header: [Destination MAC | Source MAC | Payload | CRC]
The switch reads only the Layer 2 MAC address to decide which port to forward the frame to. It never opens the payload.
🔁 What Layer 2 Actually Deals With
Addressing
MAC addresses — unique 48-bit identifiers per network card.
Framing
Groups bits into a frame with a header (source & destination MAC) and a trailer (error-check CRC).
Protocols
Ethernet (IEEE 802.3), Wi-Fi (802.11), PPP, HDLC.
Devices
Switches, bridges, network interface cards (NICs), wireless access points.
Unit
The frame.

Section 06

Layer 3 — Network Layer

Layer 3 handles logical addressing (IP) and routing — finding a path across the whole planet, hop by hop, from one network to another. This is the layer where the internet as we know it lives. Routers operate here.

Animated Diagram — A Packet Being Routed Across Networks
Sender 192.168.1.5 R1 R2 R3 Receiver 203.0.113.42 Each router looks at the destination IP and picks the next hop.
One packet, four hops. Routers exchange routes using protocols like OSPF (inside one org) and BGP (across the whole internet).
Facebook Erases Itself from the Internet (Oct 4, 2021)
Layer 3 doesn't often make front-page news — except when it fails spectacularly. On October 4, 2021, at 15:39 UTC, the social network Facebook and its subsidiaries, Messenger, Instagram, WhatsApp, Mapillary, and Oculus, became globally unavailable for a period of six to seven hours. Wikipedia's summary is stark: the outage was caused by the loss of IP routes to the Facebook Domain Name System (DNS) servers, which were all self-hosted at the time.

Cloudflare's analysis, cited widely, reported that at 15:39 UTC, Facebook made a significant number of BGP updates, including the withdrawal of routes to the IP prefixes, which included all of their authoritative nameservers. In plain English: Facebook's own engineers, during a routine backbone audit, accidentally told the rest of the internet's routers "we don't exist anymore". The Border Gateway Protocol — Layer 3's global routing protocol — obediently withdrew all paths. Facebook literally vanished from the internet's map.

One TechTarget analysis crystallised the root cause: "The root cause of this was fingers". Ad revenue lost: around $60 million in ad revenue in a single day. All from misconfiguring one layer of the OSI stack.
🌐 What Layer 3 Actually Deals With
Addressing
IP addresses (IPv4: 192.168.1.5, IPv6: 2001:db8::1). Logical, assigned by software.
Routing
Choosing the best path across many networks. Protocols: OSPF, RIP, EIGRP (inside one organisation); BGP (between organisations).
Protocols
IP (Internet Protocol), ICMP (used by ping), BGP.
Devices
Routers. Also Layer 3 switches.
Unit
The packet.

Section 07

Layer 4 — Transport Layer

Layer 4 gives you two things: reliability (or the option to skip it) and ports (so many apps can use the network at the same time). This is the layer of TCP and UDP — arguably the two most important three-letter acronyms in networking.

Animated Diagram — The TCP Three-Way Handshake
Client Server 1. SYN → 2. ← SYN-ACK 3. ACK →
TCP opens a connection with three messages before a single byte of data is sent. That's why TCP is called "reliable" and why it costs latency.
👦 TCP — the reliable delivery man
Connection-oriented (3-way handshake).
Guarantees delivery, order, no duplicates.
Retransmits lost packets.
Slower — extra overhead.
Used by: HTTP/HTTPS, SSH, SMTP, FTP.
🚀 UDP — the speedy courier
Connectionless — just fire packets.
No delivery guarantee, no ordering.
No retransmission — lost is lost.
Very fast, tiny overhead.
Used by: DNS lookups, video calls, gaming, DHCP.
🏃
When you'd pick UDP over TCP

Consider a video call. If one 30-millisecond audio packet is lost, do you want TCP to stop the whole call while it retransmits — making everyone say "hello? hello?" Or would you rather just skip that tiny gap and keep going? Video, voice, and games choose UDP for exactly this reason: timeliness beats reliability.

🔒 What Layer 4 Actually Deals With
Ports
Numbers 0–65535 that let one IP address host many services. HTTP=80, HTTPS=443, SSH=22, DNS=53.
Reliability
TCP tracks every byte and re-sends what got lost. UDP does not.
Flow control
TCP slows down the sender when the receiver's buffer fills.
Unit
The segment (TCP) or datagram (UDP).

Section 08

Layer 5 — Session Layer

The session layer opens, manages, and closes conversations between two applications. Think of it as the layer that remembers "you are logged in" and keeps a continuous conversation flowing across many separate packets. In modern TCP/IP-based networks this layer's job is largely absorbed into applications themselves, but the concept still matters.

🔒
Session Setup
login, authenticate
When you log in to Gmail, a session is established between your browser and Google's server. That "you are logged in" state is the session.
🔁
Session Maintenance
keep-alive, checkpoints
If your Zoom call briefly drops network, the session layer can resume from a checkpoint instead of restarting the whole meeting from scratch.
🔫
Session Teardown
logout, close
Clicking "Log out" cleanly closes the session. Skipping it (just closing the tab) leaves the session hanging — a small security risk.
💬
Examples in real protocols

NetBIOS, RPC (Remote Procedure Call), PPTP, and SIP (used in VoIP calls) all contain session-layer logic. In modern web applications, session state is typically managed by cookies at the application layer, not by a separate session-layer protocol.


Section 09

Layer 6 — Presentation Layer

Layer 6 is the translator and encryptor. Different computers store data differently — one may use ASCII, another EBCDIC, one big-endian, one little-endian. The presentation layer converts data into a common wire format. It also handles encryption (so nobody snooping the cable can read your data) and compression (so less data has to travel).

Animated Diagram — TLS Encryption in Action
Plain text "Hello!" Sender TLS Encryption Cipher text "a8fB@x!q∞" On the wire TLS scrambles the payload so an eavesdropper on the wire sees only noise.
This is what the "S" in HTTPS gives you — presentation-layer encryption via TLS. Same idea for WhatsApp end-to-end encryption.
🔑 What Layer 6 Actually Deals With
Translation
Character encoding (ASCII ↔ Unicode), byte order (big/little endian).
Encryption
TLS/SSL, AES, RSA. Scrambles data so only the intended receiver can read it.
Compression
gzip, JPEG, MP3, MP4 — shrink data before sending, expand on the other side.
Formats
JPEG, PNG, MP3, GIF, ASCII, Unicode — how data is represented.

Section 10

Layer 7 — Application Layer

This is the layer you touch directly. Your web browser, your email client, WhatsApp, your banking app, Zoom, PhonePe — every one of them is a Layer 7 application talking a Layer 7 protocol. HTTP, DNS, SMTP, IMAP, FTP, SSH — these are all application-layer protocols.

Animated Diagram — HTTP Request and Response
Browser you.com Web Server nginx / apache GET /index.html 200 OK + <html>... A single web page load = one or more HTTP request/response cycles at Layer 7.
Every time you open a website, this dance happens dozens of times — one round for the HTML, more for each image, script, font.
The CrowdStrike Outage — When One App Broke 8.5 Million PCs (July 19, 2024)
Layer 7 isn't just "your browser". It includes every piece of software that uses the network. When one such application misbehaves at global scale, the damage is spectacular.

Wikipedia records the day like a war report: on 19 July 2024, the American cybersecurity company CrowdStrike distributed a faulty update to its Falcon Sensor security software that caused widespread problems with Microsoft Windows computers running the software. As a result, roughly 8.5 million systems crashed and were unable to properly restart in what has been called the largest outage in the history of information technology and "historic in scale".

NPR described the human view of it: a technological meltdown left employees of airlines, banks, hospitals and emergency services around the world staring at the dreaded "blue screen of death" on Friday as their computers went inert in what is being described as a historic outage. Globally, 5,078 air flights, 4.6% of those scheduled that day, were cancelled. Delta Air Lines alone reported the revenue impact from the outage was revealed to be $380 million.

The lesson: Layer 7 code failures can propagate as fast as electricity. Nothing at Layer 1–6 was wrong. Cables were fine. Routers were fine. Wi-Fi was fine. A single bad file pushed to one security application at the top of the stack was enough to freeze critical infrastructure across dozens of countries.
🌐 What Layer 7 Actually Deals With
Protocols
HTTP, HTTPS, DNS, SMTP, POP3, IMAP, FTP, SSH, Telnet, DHCP.
You interact with
Browsers, email clients, chat apps, banking apps — anything with a screen.
Common failures
"404 Not Found", "500 Server Error", app freezes, wrong password.
Unit
The message (or "data" in generic terms).

Section 11

The TCP/IP Model — What Actually Runs the Internet

The TCP/IP model was born out of the US Department of Defense's ARPANET project. It was designed to be simple, robust, and to actually get built — not to be theoretically elegant. It has only 4 layers (or 5, depending on the textbook), and every one of them is in active use across every device you own.

Animated Diagram — OSI (7) vs TCP/IP (4) Side by Side
OSI Model — 7 layers TCP/IP Model — 4 layers 7. Application 6. Presentation 5. Session 4. Transport 3. Network 2. Data Link 1. Physical 4. Application HTTP, DNS, TLS, SMTP, FTP 3. Transport (TCP/UDP) 2. Internet (IP) 1. Network Access Ethernet, Wi-Fi, cables, MAC
TCP/IP folds OSI layers 5, 6, 7 into a single "Application" layer, and OSI layers 1 & 2 into a single "Network Access" layer.
📁 The TCP/IP Layers Explained
4. App
Application layer. Absorbs OSI's Application + Presentation + Session. Handles data format, encryption, and user-facing protocols. Where HTTP, DNS, TLS, SMTP live.
3. Transport
Transport layer. Same as OSI Layer 4. TCP for reliability, UDP for speed.
2. Internet
Internet layer. Same as OSI Layer 3. IP addressing and routing. This is where the "IP" in "TCP/IP" comes from.
1. Net Access
Network Access layer. Absorbs OSI Data Link + Physical. Handles MAC addresses, frames, and physical transmission.

Section 12

OSI vs TCP/IP — Head-to-Head

Aspect OSI Reference Model TCP/IP Model
Number of layers 7 4 (some say 5)
Developed by ISO (1984) US DoD / ARPA (1970s–80s)
Approach Model first, then build Build first, then document
Adoption Theoretical / teaching Runs the entire internet
Separates session & presentation? Yes No — merged into Application
Separates physical & data link? Yes No — merged into Network Access
Protocol dependency Protocol-independent (generic) Tied to specific protocols (TCP, UDP, IP)
Reliability guarantee Guaranteed at Layer 4 Optional (TCP yes, UDP no)
Best used for Learning, debugging, exams Actual implementation
🏆
The Practitioner's View

Engineers build in TCP/IP. Engineers talk in OSI. When a colleague says "that's a Layer 3 problem" or "we need to fix it at Layer 7", they are using OSI numbers even though the code itself is TCP/IP. Both models are worth learning — not as competitors, but as complementary tools.


Section 13

Encapsulation — How Data Actually Gets Ready to Send

As data travels down the OSI stack from Layer 7 to Layer 1, each layer wraps it in its own header (and sometimes trailer). This wrapping is called encapsulation. On the receiving end, each layer peels its header off — called decapsulation — and hands the inner payload up.

Animated Diagram — Encapsulation, Layer by Layer
L7 Application L4 Transport L3 Network L2 Data Link L1 Physical DATA TCP DATA IP TCP DATA ETH IP TCP DATA CRC 01101001 10110010 11001010 00110101... ↓ add headers Each layer adds its own control information. By the time it hits the wire, the original payload is buried under multiple headers.
This is why a packet is bigger than the message it carries — you're paying for headers at every layer.
📩
Encapsulation in one metaphor

Data = your birthday card. TCP header = the envelope with the recipient's apartment number. IP header = a bigger envelope with their street address. Ethernet header = a courier's manifest bag with the local pincode. Each wrapping is opened only by the right person. The postman never reads the card.


Section 14

End-to-End Data Flow — From One Computer to Another

Here is the picture every networking student must burn into memory. When two computers talk, the data flows down through all 7 layers on the sender, crosses the physical medium, and flows up through all 7 layers on the receiver. Every layer on the sender is virtually talking to its matching layer on the receiver — but the actual bits only travel across the wire at Layer 1.

Animated Diagram — Peer-to-Peer Data Flow (Sender L7→L1, Receiver L1→L7)
Computer A — Sender Computer B — Receiver data flows down 7 → 1 data flows up 1 → 7 7 — Application 7 — Application 6 — Presentation 6 — Presentation 5 — Session 5 — Session 4 — Transport 4 — Transport 3 — Network 3 — Network 2 — Data Link 2 — Data Link 1 — Physical 1 — Physical actual wire DOWN UP Peer-layer logical (virtual) connection Physical wire — the only real path bits travel on Actual data packet (watch it travel)
Yellow dot = one packet. It walks all the way down the sender's 7 layers, crosses the wire, then walks all the way up the receiver's 7 layers.
💬
Two Kinds of Communication — Real vs Virtual

The dashed horizontal arrows are logical (or peer-to-peer) connections. Layer 4 on Computer A believes it is talking directly to Layer 4 on Computer B — it can even use fields in the TCP header that only Layer 4 understands. But those fields aren't teleported. In reality, the message is handed down layer by layer to Layer 1, sent across the yellow wire, and reassembled up the other side. The peer illusion is what makes protocols composable.

🔁 The Full End-to-End Journey in 14 Steps
A — L7
Sender's application prepares the message: "Hi".
A — L6
Encrypt and/or compress it.
A — L5
Attach it to the ongoing session.
A — L4
Wrap in a TCP segment with source and destination ports.
A — L3
Wrap in an IP packet with source and destination IPs.
A — L2
Wrap in an Ethernet or Wi-Fi frame with MAC addresses.
A — L1
Convert to bits — voltages, light, or radio waves.
Wire
Bits travel across the cable, Wi-Fi, or fibre — possibly through many routers.
B — L1
Receiver's hardware detects the electrical signal and reads the bits.
B — L2
Reassemble into a frame, verify the CRC, strip the Ethernet header.
B — L3
Confirm this is the right destination IP, strip the IP header.
B — L4
Send an ACK back, deliver the segment to the correct port.
B — L5
Route to the correct application session.
B — L6
Decrypt and/or decompress.
B — L7
Application receives the plain text: "Hi". Notification pops up.
Why This Diagram Matters

Every network problem in the world can be located on this diagram. A slow download? Look at Layer 4 (TCP retransmissions). A "site not found" error? Layer 3 or 7 (DNS). A blank Wi-Fi icon? Layer 1 or 2. Once you know which side of the wire and which layer, the fix becomes obvious — often in under a minute.


Section 15

A Packet's Life — Sending "Hi" on WhatsApp

Let's ground everything by tracing one WhatsApp message from your phone in Sirhind to a friend's phone in Delhi. Every OSI layer is doing real work.

L7
Application
You type "Hi" and tap send. WhatsApp packages it as a Signal-protocol message with your ID and your friend's ID.
L6
Presentation
The message gets end-to-end encrypted. Now it's ciphertext that even WhatsApp's own servers can't read.
L5
Session
Your phone's persistent connection to WhatsApp servers is used — no re-login required for every message.
L4
Transport
Wrapped in a TCP segment addressed to port 443 (HTTPS). TCP ensures nothing is lost.
L3
Network
Wrapped in an IP packet with your public IP as source and WhatsApp's server IP as destination.
L2
Data Link
Wrapped in a Wi-Fi frame with your phone's MAC address and your router's MAC address.
L1
Physical
Converted to 2.4 GHz radio waves. The waves reach your router, become electrical signals on Ethernet, then light pulses in your ISP's fibre, then across BharatNet, then back down all 7 layers on your friend's phone. Total: about 50 milliseconds.

Section 16

Diagnosing Real Problems by Layer

The real reason we teach the OSI model in 2026 is that it is the fastest debugging framework in networking. When something breaks, walk the layers — usually from the bottom up.

🔌
Layer 1 — Physical
Is the cable plugged in? Is the Wi-Fi on? Is the router powered? Is there a link light? Try a different cable or port.
"No connection at all"
📡
Layer 2 — Data Link
Can your device get an IP from DHCP? Is your MAC address on the correct VLAN? Any duplicate MAC in the network?
"Wi-Fi connected but no internet"
🌐
Layer 3 — Network
Can you ping the router? Can you ping 8.8.8.8? Does traceroute reveal a dead router in the middle?
"Some sites work, others don't"
🛡️
Layer 4 — Transport
Is the port open? Is a firewall blocking TCP 443? Are TCP retransmissions high (slow connection)?
"Connects but timeouts"
🔒
Layer 6 — Presentation
Is the TLS certificate expired? Character encoding mismatched? Content unexpectedly compressed?
"SSL error", "encoding garbled"
🖥️
Layer 7 — Application
Is the server returning a 500? Did DNS resolve? Is the app itself crashing? Is it a bug in the code you just deployed?
"Everything else works, this app doesn't"

Section 17

Real Newspaper Cases — Layer by Layer

Layer Real Case What Went Wrong
L1 Physical Red Sea undersea cable cuts (Sept 2025) A ship's anchor severed submarine cables carrying about 25% of Asia–Europe internet traffic. Pure Layer 1 damage.
L2 Data Link Broadcast storms in early enterprise LANs Misconfigured switches (no spanning-tree protocol) caused frames to loop endlessly, saturating the LAN.
L3 Network Facebook / Meta outage (Oct 4, 2021) A faulty BGP configuration update withdrew Meta's IP routes from the global internet, taking Facebook, Instagram, and WhatsApp offline for six hours.
L4 Transport SYN flood DDoS attacks Attackers open millions of half-finished TCP handshakes, exhausting the server's connection table. Classic Layer 4 attack.
L6 Presentation Expired TLS certificates (recurring, all sites) When a website's TLS certificate expires, browsers show "your connection is not private". Nothing else is broken — just Layer 6.
L7 Application CrowdStrike outage (July 19, 2024) A single faulty Falcon Sensor update crashed 8.5 million Windows machines worldwide, grounding airlines, freezing banks, halting hospitals. Layer 7 code, global blast radius.

Section 18

Golden Rules

🔒 OSI & TCP/IP — Non-Negotiable Rules
1
OSI is the language, TCP/IP is the reality. Learn both. Talk in OSI layers ("that's a Layer 3 issue") but know that the code is TCP/IP.
2
Each layer only talks to the layer above and below. A well-designed protocol never reaches across the stack. Break this rule and you get systems as fragile as Facebook's 2021 architecture, where the same network carried live traffic and recovery tools.
3
Debug from the bottom up. Check the cable before you blame the application. 60% of "the internet is down" tickets get fixed by touching Layer 1.
4
Layer 3 (BGP + IP) failures scale to the whole planet. The Facebook 2021 outage — six hours, an estimated $60 million in lost ad revenue — was one router configuration line. Test route changes in a lab first, always.
5
Layer 7 (Application) failures scale to every screen. CrowdStrike 2024 — 8.5 million machines — is proof that a single file pushed to a single application can freeze critical infrastructure. Gradual rollouts and canary deployments are not optional.
6
TCP for reliability, UDP for timeliness. Don't fight the transport layer — pick the right tool. Streaming, voice, games: UDP. File transfer, web pages, email: TCP.
7
Encapsulation costs bytes but buys sanity. Every layer adds a header. That overhead is the price of a modular internet where anyone can build a new application without touching the routers.