š OSI Model Explained
Understanding How Network Communication Works
Series: Networking Fundamentals for Cloud & DevOps ā Part 2 of 6
The OSI Model is one of those topics where you should understand the purpose of the layers rather than memorize definitions. Once you understand what each layer is responsible for, concepts like MAC addresses, IP addresses, ports, TCP/UDP, and encapsulation start fitting together naturally.
What is the OSI Model?
OSI = Open Systems Interconnection.
The OSI Model is a 7-layer conceptual model that divides network communication into different responsibilities.
The goal of networking is simple: allow two hosts to communicate and exchange data, and the OSI Model helps us understand what happens at each stage of that communication.
Think of it like a human body. The body has different systems ā nervous, muscular, respiratory, etc. ā and each has a specific responsibility.
Similarly, networking is divided into 7 layers, with each layer handling a specific part of communication.
The 7 Layers
7 Application 6 Presentation 5 Session 4 Transport 3 Network 2 Data Link 1 Physical
For now, we'll focus more heavily on Layers 1ā4, because these directly connect with what we learned in Part 1 about repeaters, switches, routers, IPs, and MAC addresses.
1. Layer 1 ā Physical
Purpose: Transporting bits
Computers ultimately deal with:
10110100101001010...
These are bits ā 0s and 1s.
Layer 1 is responsible for physically transporting those bits from one device to another using things like:
- Ethernet cables
- Fiber
- Wi-Fi radio signals
- Repeaters
- Hubs
Analogy
Think of Layer 1 as the road itself.
It doesn't care who is sending something or where that information ultimately needs to go. It simply provides the physical medium through which something can travel.
Host āāā Cable / Wi-Fi / Fiber āāā Host
The medium could be copper, fiber, or wireless radio.
The important idea is:
Layer 1 = Bits + physical medium
2. Layer 2 ā Data Link
Purpose: Hop-to-hop communication
Layer 2 works on top of the physical medium and handles communication between directly connected devices ā one hop at a time.
Its addressing scheme is the:
MAC Address
A MAC address is typically 48 bits, represented as 12 hexadecimal digits.
Example:
94:65:9C:3B:8A:E5
Every network interface (NIC) has a MAC address.
Layer 2 technologies include:
- NICs
- Ethernet
- Switches
- MAC addresses
Why "hop-to-hop"?
Suppose we have:
Host A ā Router 1 ā Router 2 ā Router 3 ā Host B
There are multiple hops.
Layer 2 communication is concerned with the current hop, not the entire journey.
For example:
Host A ā Router 1
Then:
Router 1 ā Router 2
Then:
Router 2 ā Router 3
The Layer 2 information can change at every hop.
Analogy
Think of sending a package through multiple delivery centers.
Each delivery center only needs to know:
"Where should this package go next?"
It doesn't personally deliver the package all the way to the final destination.
That's hop-to-hop communication.
3. Layer 3 ā Network
Purpose: End-to-end addressing and routing
Layer 3 uses IP addresses.
Example:
Source IP: 10.1.1.11 Destination IP: 10.8.8.88
Unlike MAC addresses, IP addresses identify the source and final destination of the communication.
Layer 3 is where routers operate and where routing between different networks happens.
Host A 10.1.1.11 ā ā Router ā ā Router ā ā Router ā ā Host B 10.8.8.88
The routers look at the destination IP and determine where to forward the packet next.
Analogy
Going back to our package example:
- IP address = final destination address
- MAC address = next delivery location/person
- Router = delivery center deciding where the package goes next
The Most Important Difference: MAC vs IP
This is VERY important.
Suppose:
Host A IP = 10.1.1.11 MAC = a1a1 wants to communicate with: Host B IP = 10.8.8.88 MAC = e8e8
The IP addresses represent the end-to-end communication:
10.1.1.11 āāāāāāāāāāāāāāāāāāāāāāāā 10.8.8.88
END TO END
But MAC addresses are used for each individual hop.
For example:
a1a1 ā b2b2 b3b3 ā c4c4 c5c5 ā d6d6 d7d7 ā e8e8
So remember:
Layer 3 IP ā End-to-end Source IP ā Destination IP Layer 2 MAC ā Hop-to-hop Current device ā Next device
This explains something very important about routers:
Routers forward packets between networks, but the Layer 2 frame is rebuilt for each hop.
The IP packet is carried through the journey, while the Layer 2 addressing changes as the packet moves from one link to the next.
Put Everything You've Learned Together
Now the previous concepts start connecting:
NETWORK
ā
āāāāāāāāāāā“āāāāāāāāāā
ā ā
Host Host
ā ā
Layer 3 Layer 3
IP IP
ā ā
Layer 2 Layer 2
MAC MAC
ā ā
Layer 1 Layer 1
Physical Physical
And the devices:
| Layer | Main concept | Examples |
|---|---|---|
| L1 Physical | Bits / signals | Cable, Fiber, Wi-Fi, Repeater, Hub |
| L2 Data Link | MAC + hop-to-hop | NIC, Switch, Bridge |
| L3 Network | IP + routing | Router, IP-enabled devices |
Easy memory
L1 = Bits L2 = MAC / Hop-to-hop L3 = IP / End-to-end
4. Layer 4 ā Transport
Purpose: Service-to-Service communication
Now we reach an important problem.
Layer 3 gets the data to the correct host using an IP address.
But a host can run many services at the same time.
For example, your laptop could have:
Browser ā HTTPS SSH ā SSH Chat app ā UDP Game ā TCP/UDP
All of them use the same IP address.
So we need another addressing mechanism to identify which service/application should receive the data.
That is the job of:
Layer 4 ā Ports
IP vs Port
Think:
IP address = Which machine? Port = Which service on that machine?
For example:
192.168.1.10:443
192.168.1.10
ā
āāā Host
ā
āāā Port 443 ā HTTPS service
So:
IP gets you to the host; port gets you to the service on that host.
This is one of the most important concepts to carry forward into Cloud and DevOps.
TCP and UDP
Layer 4 mainly uses:
- TCP ā Transmission Control Protocol
- UDP ā User Datagram Protocol
Both use ports.
The port range is:
0 āāāāāāāāāāāāāāāāāāāāāāāāāāāāā 65535
TCP
TCP favors reliability.
It provides mechanisms such as:
- Connection establishment
- Reliable delivery
- Ordering
- Retransmission
- Flow/congestion control
Examples:
HTTPS ā TCP/443 HTTP ā TCP/80 SSH ā TCP/22
When reliability and ordered delivery matter, TCP provides the mechanisms needed to make that communication reliable.
UDP
UDP favors efficiency and low overhead.
UDP does not provide TCP's connection-oriented reliability mechanisms.
Examples:
DNS ā commonly UDP/53 QUIC ā UDP/443
The important idea is not simply to memorize which protocol uses which port.
Remember the trade-off:
TCP ā Reliability UDP ā Efficiency / low overhead
Server Port vs Client Port
This is another important Layer 4 concept.
Suppose you open:
https://example.com
The server might be listening on:
TCP/443
Your computer, however, needs a source port for the connection.
It can choose an ephemeral (temporary) source port.
For example:
Client Server 192.168.1.10:49152 āāāāāāāāāāāāāāāāāā 93.184.216.34:443
Here:
49152 = client's temporary / ephemeral source port 443 = server's listening service port
The response comes back:
93.184.216.34:443 āāāāāāāāāāāāāāāāāā 192.168.1.10:49152
The client uses that source port to associate the response with the correct connection/application.
Small correction to the common wording
Client ports are often described as "random", but more accurately they are dynamically/ephemerally allocated by the operating system.
Multiple Connections to the Same Server
This is where ports become really useful.
Your computer can have multiple connections to the same server IP and destination port:
TCP 192.168.1.10:6666 āāāā 3.3.3.3:80 TCP 192.168.1.10:9999 āāāā 3.3.3.3:80 TCP 192.168.1.10:5555 āāāā 3.3.3.3:80
Notice:
Destination IP = same Destination port = same Source ports = different
Therefore, the OS can distinguish between the different connections.
This is one reason the source port matters.
Combine L2, L3 and L4
Suppose:
Client: IP = 10.1.1.11 MAC = a1a1 Port = 1025
And:
Server: IP = 192.168.1.99 MAC = 8AE5 Port = 80
As the data moves down the OSI stack, additional information is added.
Layer 4 ā TCP
Source Port: 1025 Destination Port: 80
Layer 3 ā IP
Source IP: 10.1.1.11 Destination IP: 192.168.1.99
Layer 2 ā Ethernet
Source MAC: a1a1 Destination MAC: 8AE5
Layer 1 ā Bits
010101010101...
This gives us the hierarchy:
L2 ā MAC ā Which device on this hop? L3 ā IP ā Which host/network? L4 ā Port ā Which service?
This is one of the most important things to remember.
Layers 5, 6 and 7
The distinction between Layers 5, 6 and 7 is somewhat vague in modern networking.
The OSI Model is a conceptual model, not a strict rule that every modern protocol must fit perfectly into exactly one layer.
So don't get obsessed with forcing every modern protocol into one specific OSI layer.
Layer 5 ā Session
Responsible conceptually for:
- Establishing communication sessions
- Maintaining sessions
- Terminating sessions
Think of it as managing the conversation/session between applications.
Layer 6 ā Presentation
Responsible conceptually for how data is represented.
Examples include:
- Encoding
- Encryption/decryption
- Compression
Think:
How should the data be represented so the other side can understand it?
Layer 7 ā Application
This is the layer closest to the applications/services that use networking.
Examples:
HTTP HTTPS DNS FTP SMTP SSH
These are protocols/services that applications use to communicate over a network.
OSI vs TCP/IP Model
In real-world networking, you'll commonly encounter the TCP/IP model.
The simplified mapping is:
OSI TCP/IP
7 Application āāāāāāāā
6 Presentation āāāā Application
5 Session āāāāāāāā
4 Transport āāāāāāāāāāāā Transport / Host-to-Host
3 Network āāāāāāāāāāāā Internet
2 Data Link āāāāāāāā
1 Physical āāāā Network Access
āāāāāāāāā
So TCP/IP essentially combines some of the OSI layers.
For Cloud and DevOps, you'll encounter the TCP/IP model frequently, but the OSI model remains extremely useful for reasoning about networking problems.
Encapsulation ā VERY IMPORTANT
Now we come to one of the most useful concepts.
When sending data, it moves down the layers.
Application
ā
Transport
ā
Network
ā
Data Link
ā
Physical
Each layer adds its own information.
This process is called:
Encapsulation
Suppose the application creates:
DATA
At Layer 4:
DATA + TCP header
At Layer 3:
DATA + TCP header + IP header
At Layer 2:
DATA + TCP header + IP header + Ethernet header
At Layer 1:
101010101010...
The complete flow:
Application
ā
Transport
ā
Network
ā
Data Link
ā
Physical
Each layer adds information needed for its own responsibility.
De-encapsulation
The receiving machine does the opposite.
The incoming bits move upward:
Physical
ā
Data Link
ā
Network
ā
Transport
ā
Application
Each layer processes and removes the information added by the corresponding sending layer.
This is called:
De-encapsulation
So the overall idea is:
Sender Receiver Data Data ā ā TCP + Data TCP + Data ā ā IP + TCP + Data IP + TCP + Data ā ā Ethernet + IP + TCP + Data Ethernet + IP + TCP + Data ā ā Bits Bits
PDU Names
Another thing worth remembering is the name given to the data at different layers.
| Layer | PDU |
|---|---|
| L7āL5 | Data |
| L4 | Segment (TCP) / Datagram (UDP) |
| L3 | Packet |
| L2 | Frame |
| L1 | Bits |
So you can visualize it like this:
DATA
ā
āāāāāāāāāāāāāāāāāāā
L4 ā TCP ā DATA ā ā Segment
āāāāāāāāāāāāāāāāāāā
ā
āāāāāāāāāāāāāāāāāāāāāāāāā
L3 ā IP ā TCP ā DATA ā ā Packet
āāāāāāāāāāāāāāāāāāāāāāāāā
ā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
L2 ā L2 ā IP ā TCP ā DATA ā ā Frame
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā
101010101010101010...
ā
Bits
The names give you a useful mental hierarchy:
Data ā Segment ā Packet ā Frame ā Bits
The Complete Picture š„
This is the mental model I'd recommend remembering:
L7 Application
ā
L6 Presentation
ā
L5 Session
ā
L4 Transport
āāā Port
āāā TCP / UDP
āāā Service-to-Service
ā
L3 Network
āāā IP
āāā Routing
āāā End-to-End
ā
L2 Data Link
āāā MAC
āāā Switching
āāā Hop-to-Hop
ā
L1 Physical
āāā Bits
āāā Cable / Wi-Fi / Fiber
And the 4 most important ideas for your Cloud + DevOps learning:
L1 ā Move bits L2 ā Move frames hop-to-hop using MAC L3 ā Move packets between hosts/networks using IP L4 ā Deliver data to the correct service using ports
This is the foundation you'll keep using when working with:
- Security Groups
- NACLs
- Load Balancers
- Target Groups
- VPCs
- Route Tables
- TCP/UDP
- Troubleshooting connectivity
- Network access problems
The AWS terminology will change, but the underlying networking concepts remain the same.
What's Next
Now that we understand how communication is divided into layers, the next step is to go deeper into the mechanisms that make those layers actually work ā especially MAC addressing, ARP, switching, IP addressing, routing, TCP/UDP, and how packets move through a real network.
Part 2 of 6 ā Networking Fundamentals for Cloud & DevOps
A prerequisite series before diving deeper into AWS VPC, subnets, routing, security groups, and network troubleshooting.
Top comments (0)