The OSI model is a framework (a kind of plan or guide) that explains how data travels from one computer to another over a network. It breaks the whole journey down into 7 layers, and each layer has its own specific job.
Different companies build different networking equipment and software.
Compatibility Problems
Without a shared standard, a router made by one company might not work well with a switch made by another.
One Common Language
The OSI model gives everyone the same structure and language to follow.
Easier Troubleshooting
If something goes wrong, you know exactly which layer to check first.
Think of sending a letter through the post office. There are several steps involved: writing the letter, putting it in an envelope, addressing it, handing it to the post office, transporting it, delivering it, and finally the receiver opening it. Each of these steps is like one layer.
Decides things like how many volts represent a 1 or a 0, and how fast the bits are sent.
It does NOT understand what the data means, it just carries the electrical or light signals.
Real-world example: The Ethernet cable plugged into your computer, or the Wi-Fi signals in the air.
Key devices: Hub, Repeater, Cable, NIC (at the physical signal level)
What it does: Makes sure data is transferred reliably between two devices that are directly connected on the same network.
Takes the raw bits from Layer 1 and organizes them into frames (small bundles of data).
Uses MAC addresses to identify devices on the local network.
Handles error detection (it can tell if data got corrupted during transmission).
Has two sub-parts:
MAC (Media Access Control) – controls who gets to use the network at a given time.
LLC (Logical Link Control) – identifies which network layer protocol is being used.
Real-world example: Your switch looks at MAC addresses to decide which device to send data to. That is Layer 2 work.
Key devices: Switch, Bridge, NIC
Key protocols: Ethernet, Wi-Fi (802.11), PPP
What it does: Handles moving data across different networks (this is called routing). This is where IP addresses come in.
Breaks data into packets and adds the source and destination IP addresses.
Routers work at this layer. They read IP addresses and decide the best path to forward each packet.
Handles logical addressing (IP addresses, unlike MAC addresses which are physical).
Does routing, which means figuring out the best path from source to destination across multiple networks.
Real-world example: When you visit a website, your data packet travels across many different networks (your home network, your ISP’s network, the internet backbone, and the destination network). Routers at this layer guide it along the way.
Key devices: Router, Layer 3 Switch
Key protocols: IP (IPv4, IPv6), ICMP (used by ping), ARP
What it does: Makes sure data is delivered completely and reliably between two applications.
Breaks data into segments and puts them back together at the destination.
Handles error correction and flow control (making sure data is not sent faster than the receiver can handle).
Two main protocols work at this layer:
TCP (Transmission Control Protocol) – reliable, ordered, error-checked delivery. Like a registered post, you get a confirmation of delivery.
UDP (User Datagram Protocol) – fast, but there’s no guarantee of delivery. Like dropping a letter in a mailbox, there’s no receipt.
Uses port numbers to identify which application the data belongs to.
TCP vs UDP:
TCP
UDP
Reliability
Reliable (confirms delivery)
No guarantee
Speed
Slower (due to checks)
Faster
Use cases
Websites, email, file download
Gaming, video streaming, DNS
Connection
Connection-based (handshake needed)
Connectionless
Key protocols: TCP, UDP
What it does: Manages the session (the ongoing conversation) between two applications.
Opens, manages, and closes sessions between applications.
Think of a session like a phone call. Layer 5 handles picking up (opening), the conversation, and hanging up (closing).
Handles synchronization. If the connection drops in the middle of a transfer, it can pick up again from where it left off (this is called checkpointing).
Handles dialog control, meaning whether both sides talk one at a time (half-duplex) or at the same time (full-duplex).
Real-world example: When you log in to Netflix, a session is created. It stays open as long as you are watching. When you close the app, the session ends.
What it does: Works as a translator between the application and the network. It formats, encrypts, and compresses data.
Converts data into a format that the receiving application can understand.
Encryption and Decryption – scrambles data for security (HTTPS uses encryption at this layer).
Compression – shrinks the size of data before sending it.
Data Format Translation – for example, converting a JPG image into binary data and back again.
Real-world example: When you send an email with a photo attached, the photo is encoded (often in base64) at this layer. When the receiver gets it, it is decoded back into a photo.
When data is sent, it travels down through all 7 layers on the sender’s side. When it reaches the destination, it travels back up through all 7 layers on the receiver’s side.
graph TD
subgraph Sender["SENDER (Your Computer)"]
S7["7. Application Layer<br/>HTTP request created"] --> S6["6. Presentation Layer<br/>Encrypt, compress"]
S6 --> S5["5. Session Layer<br/>Session opened"]
S5 --> S4["4. Transport Layer<br/>Segments, ports, TCP/UDP"]
S4 --> S3["3. Network Layer<br/>Add IP addresses, packets"]
S3 --> S2["2. Data Link Layer<br/>Add MAC addresses, frames"]
S2 --> S1["1. Physical Layer<br/>Convert to bits/signals"]
end
subgraph Receiver["RECEIVER (Web Server)"]
R1["1. Physical Layer<br/>Receive bits/signals"] --> R2["2. Data Link Layer<br/>Read MAC, remove frame"]
R2 --> R3["3. Network Layer<br/>Read IP, decide next hop"]
R3 --> R4["4. Transport Layer<br/>Reassemble segments, check errors"]
R4 --> R5["5. Session Layer<br/>Session managed"]
R5 --> R6["6. Presentation Layer<br/>Decrypt, decompress"]
R6 --> R7["7. Application Layer<br/>HTTP request received"]
end
S1 -. "travels through cables, Wi-Fi, routers" .-> R1
The key idea: As data goes down the layers, each layer adds its own header (a small piece of extra information) to it. This is called encapsulation. When the data reaches the receiver and goes back up, each layer removes its own header. This is called decapsulation.
This is one of the most important ideas in networking. Let’s walk through what actually happens when you type www.google.com into your browser.
You type www.google.com in your browser
Your browser (Application Layer) creates an HTTP GET request.
DNS Resolution
Your computer doesn’t know Google’s IP address yet, so it asks DNS: “What is the IP of google.com?”
DNS replies: “It is 142.250.182.46”
Now your computer knows where to send the request.
Data is prepared and sent down through the OSI layers
Application Layer: The HTTP request is created.
Transport Layer: The data is broken into segments. A TCP connection is set up with Google’s server first, using a 3-way handshake (SYN, SYN-ACK, ACK). Port 443 (HTTPS) is used.
Network Layer: An IP packet is created. Your IP is the source, Google’s IP is the destination.
Data Link Layer: A frame is created with MAC addresses. The source MAC is your computer’s NIC. The destination MAC is your router’s MAC.
Physical Layer: The data is converted into electrical signals (or Wi-Fi radio waves).
The packet leaves your computer and goes to your router
Your router receives the frame.
It removes the Data Link Layer frame, since that part was only meant for the local hop.
The router reads the IP packet and checks its routing table to find the best path to Google’s IP.
It creates a new frame for the next hop and sends it out.
The packet hops through the internet
The packet passes through many routers, and each one is called a hop.
Each router reads the destination IP and forwards the packet a step closer to Google.
You can actually see these hops using the traceroute command.
The packet arrives at Google’s server
Google’s server receives the packet.
The data travels back UP through the OSI layers, with each step removing its header.
The HTTP request is finally handed to Google’s web application.
Google sends back the response
The same process happens again, but in reverse.
Google’s server sends the web page data back to your IP address.
Your browser receives the response
Your browser reads the HTML, CSS, and JavaScript files it gets back.