ismile@portfolio:~$ cat notes/0009-osi-model-data-transmission.md
OSI Model Data Transmission
When you type “hello” and send it from one computer to another, your data doesn’t go as a simple string. It travels through the OSI model (7 layers), getting wrapped, sent, unpacked, and finally shown as text again.
Let’s go step by step with a real mental + visual model.
🧠 Big Picture First (What actually happens)
Think of it like this:
Your message goes DOWN 7 layers in your computer → travels over the network → then goes UP 7 layers in the receiver’s computer.
Each layer has a job and adds (or removes) its own information.
🧱 OSI Model Overview
OSI has 7 layers:
| Layer | Name | Job |
|---|---|---|
| 7 | Application | User interface (your “hello”) |
| 6 | Presentation | Encoding, encryption |
| 5 | Session | Starts/manages connection |
| 4 | Transport | Splits data, reliability (TCP) |
| 3 | Network | Routing (IP address) |
| 2 | Data Link | MAC address, local delivery |
| 1 | Physical | Electrical signals / WiFi waves |
📤 Step-by-Step: Sending “hello”
Let’s assume you send “hello” from Computer A → Computer B
🟢 1. Application Layer (Layer 7)
You type:
hello
- This is just raw text
- Example apps: browser, WhatsApp, terminal
👉 Nothing network-related yet.
🟡 2. Presentation Layer (Layer 6)
Now the system prepares data:
- Converts text → binary (ASCII/UTF-8)
- May compress or encrypt (HTTPS uses this)
Example:
hello → 01101000 01100101 01101100 01101100 01101111
🔵 3. Session Layer (Layer 5)
- Creates a session between your computer and destination
- Think: “start conversation”
Example:
- Login session
- Connection tracking
👉 It ensures communication is active and organized.
🟠 4. Transport Layer (Layer 4)
Now things get important.
This layer:
- Breaks data into chunks (segments)
- Adds port number
- Uses TCP or UDP
Example:
Segment 1:
[hello data] + Source Port: 5000 + Destination Port: 443
If using TCP:
- ensures delivery
- checks order
- resends if lost
👉 This is where reliability is handled.
🔴 5. Network Layer (Layer 3)
Now your message gets:
- Source IP
- Destination IP
- Routing info
Example:
From: 192.168.1.10
To: 172.217.160.78
👉 Router decides:
“Which path should this packet take?”
Like Google Maps for data.
🟣 6. Data Link Layer (Layer 2)
Now we move inside your local network (WiFi/Ethernet):
Adds:
- MAC address of sender
- MAC address of next hop (router)
Example:
From MAC: AA:BB:CC
To MAC: FF:EE:DD (router)
👉 This is how data moves inside LAN.
⚫ 7. Physical Layer (Layer 1)
Finally:
- Data becomes signals:
- electrical pulses (cable)
- radio waves (WiFi)
- light (fiber)
👉 Sends raw bits:
101010101010001010
🌍 Travel Across Network
Now the packet moves:
Computer → Router → ISP → Multiple routers → Destination network
Each router:
- reads Layer 3 (IP)
- decides next hop
- does NOT care about “hello”
📥 Receiving Side (Reverse Process)
Now Computer B receives signals:
It goes UP the OSI layers:
🔵 Layer 1 → 2 → 3 → 4 (Decapsulation)
Each layer removes its header:
- Physical → receives bits
- Data Link → checks MAC
- Network → checks IP
- Transport → reorders & verifies packets
🟡 Layer 5 → 6 → 7
- Session: keeps connection active
- Presentation: decrypts + converts binary → text
- Application: shows:
hello
🔁 Full Flow Visualization
SENDER COMPUTER
────────────────────────────
"hello"
↓ Application (L7)
encode text
↓ Presentation (L6)
binary + encryption
↓ Session (L5)
session info added
↓ Transport (L4)
segment + ports (TCP)
↓ Network (L3)
IP addresses added
↓ Data Link (L2)
MAC addresses added
↓ Physical (L1)
bits → signal
────────────────────────────
NETWORK
routers forward using IP
────────────────────────────
RECEIVER COMPUTER
────────────────────────────
signal → bits
↑ Physical
remove MAC
↑ Data Link
check IP
↑ Network
rebuild segments
↑ Transport
decrypt session
↑ Session
decode binary → text
↑ Presentation
show "hello"
↑ Application
────────────────────────────
🧠 Key Idea to Remember
Each layer only talks to its “peer layer” on the other machine.
So:
- Transport layer thinks it is talking to Transport layer
- Network layer talks to Network layer
- etc.
Even though physically, data travels downward → across network → upward.
⚡ Real-Life Analogy
Imagine sending a gift:
- Application → you write message (“hello”)
- Presentation → you wrap gift nicely
- Session → you open a chat session
- Transport → break into boxes, number them
- Network → writes full address
- Data Link → local delivery label (post office)
- Physical → delivery truck / bike / wire
Receiver unwraps everything step-by-step.