DEV Community

Tejas Shinkar
Tejas Shinkar

Posted on

OSI Model Explained — Understanding How Network Communication Works

🌐 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)