🌐 Networking 101 β€” OSI Layers Explained

How Data Travels β€” From Wires to APIs

πŸ’­
"Every time you load a webpage, send a message, or stream a video β€” data travels across networks. But how does it actually move?"

To understand that, we use the OSI model β€” a layered framework that breaks down communication into 7 steps. Each layer has a job. Together, they make the internet work.

🧩 The OSI Model β€” Overview

For system design, we focus mostly on Layer 3 (Network), Layer 4 (Transport), and Layer 7 (Application)

7

Application

User-facing protocols (HTTP, etc.)

6

Presentation

Data formatting and encryption

5

Session

Start, manage, and end sessions

4

Transport

Reliable or fast delivery (TCP/UDP)

3

Network

Routing and addressing (IP)

2

Data Link

Frame transmission over local network

1

Physical

Electrical signals and hardware

⚑ Layer 1: Physical Layer

The foundation β€” raw bits, cables, and electrical signals

What it does:

  • β€’Transmits raw bits over physical medium
  • β€’Defines electrical and physical specifications
  • β€’Handles voltage levels, timing, and distances
  • β€’Physical topology and connections

Analogy: It's the roads and highways β€” the actual physical infrastructure that carries everything.

Examples:

Ethernet CablesFiber OpticRadio WavesUSBHubsRepeaters

πŸ”— Layer 2: Data Link Layer

Local network traffic controller β€” manages frames within the same network

What it does:

  • β€’Frames data for transmission over physical medium
  • β€’Handles MAC addresses for local delivery
  • β€’Error detection and correction
  • β€’Flow control between adjacent nodes

Analogy: It's the local postal service β€” handling delivery within your neighborhood using house addresses.

Examples:

EthernetWiFi (802.11)BluetoothPPPSwitches

🌐 Layer 3: Network Layer

Connects different networks and ensures data reaches the correct destination

What it does:

  • β€’Handles routing and addressing across networks
  • β€’Moves packets from one network to another
  • β€’Assign IP addresses
  • β€’Fragment and reassemble data

Analogy: It's the GPS system β€” figuring out how to get data from your device to a server across the world.

Examples:

IP (IPv4/IPv6)RoutersICMP (ping)

🚚 Layer 4: Transport Layer

Decides how data is delivered β€” reliably or quickly β€” depending on the use case

What it does:

  • β€’Manages end-to-end communication
  • β€’Ensures reliable or fast delivery
  • β€’Open and close connections
  • β€’Handle retransmissions and acknowledgments

Analogy: It's the delivery truck β€” deciding whether to guarantee delivery (TCP) or send it quickly without confirmation (UDP).

Examples:

TCP (reliable)UDP (fast)

🀝 Layer 5: Session Layer

Connection manager β€” establishes, maintains, and terminates conversations

What it does:

  • β€’Establishes sessions between applications
  • β€’Manages ongoing conversations
  • β€’Handles session checkpoints and recovery
  • β€’Terminates sessions when done

Analogy: It's the meeting coordinator β€” scheduling, managing, and ending conversations between apps.

Examples:

NetBIOSRPCSQL SessionsLDAPSMB

πŸ” Layer 6: Presentation Layer

Data translator and security guard β€” formats, encrypts, and compresses data

What it does:

  • β€’Encrypts and decrypts data for security
  • β€’Compresses data to save bandwidth
  • β€’Converts data formats (ASCII, JPEG, etc.)
  • β€’Character encoding and data representation

Analogy: It's the translator and security checkpoint β€” making sure data is in the right format and secure.

Examples:

TLS/SSLJPEGGIFASCIIGZIPMPEG

🧾 Layer 7: Application Layer

Where developers interact β€” designing APIs, sending requests, building user-facing systems

What it does:

  • β€’Defines how applications communicate
  • β€’Handles user-facing protocols and APIs
  • β€’Format requests and responses
  • β€’Handle authentication, headers, cookies

Analogy: It's the spoken language between apps β€” the actual content of the message.

Examples:

HTTP/HTTPSRESTGraphQLgRPCWebSocketsSMTP

πŸ”„ How "Hi" Message Travels Through Layers

Step-by-step journey from your chat app to your friend's phone

πŸ“¦ When you send a "Hi" message, it travels down the OSI layers on your device, across the network, and back up the layers on the receiver's device.

πŸ“€ Sending Side: Going Down

7

Layer 7 – Application

User clicks 'Send' on chat app

App creates HTTP/WebSocket request with 'Hi' message

6

Layer 6 – Presentation

Message encoded and encrypted

JSON formatting + TLS encryption applied

5

Layer 5 – Session

Session established

TLS handshake completed, conversation tracked

4

Layer 4 – Transport

Message split into segments

TCP adds headers for sequencing and port numbers

3

Layer 3 – Network

Wrapped in IP packet

IP header with source/destination addresses added

2

Layer 2 – Data Link

Encapsulated in frame

MAC addresses and error detection codes added

1

Layer 1 – Physical

Converted to signals

Electrical signals sent through cables/wireless

πŸ“₯ Receiving Side: Going Up

1

Layer 1 – Physical

Signal received

Electrical/wireless signals converted back to data

2

Layer 2 – Data Link

Frame extracted

MAC addresses checked, error detection verified

3

Layer 3 – Network

IP packet read

Destination IP confirmed, packet forwarded up

4

Layer 4 – Transport

Segments reassembled

TCP reorders segments, acknowledges receipt

5

Layer 5 – Session

Session resumed

Conversation state maintained

6

Layer 6 – Presentation

Message decrypted & decoded

TLS decryption, JSON parsing applied

7

Layer 7 – Application

Message delivered to app

'Hi' message appears in chat interface

🌐

Traveling Across the Network

The encapsulated message travels through routers, switches, and cables to reach the destination

🧠 Mental Hook: "Wrapping the Gift"

Think of each layer as wrapping the message in a new box

🎁

Layer 7

The message itself

πŸ“¦

Layer 6

Format and lock the box

πŸ“¬

Layer 5

Track the delivery

🚚

Layer 4

Choose delivery method

πŸ—ΊοΈ

Layer 3

Add address label

🏒

Layer 2

Add building routing

⚑

Layer 1

Send down the wire

Key Insight: Each layer adds a header β€” like a label or instruction β€” to help the message reach its destination and be understood.

🧠

Final Thought

"Understanding the OSI model helps you reason about every part of system communication β€” from physical cables to APIs."

And as we move forward in this course, we'll explore how these layers shape load balancing, transport protocols, and global delivery.