Chapter 02 — The OSI & TCP/IP Models

Chapter 02 — The OSI & TCP/IP Models

Hey everyone! Welcome back to Namaste Computer Networks! 🙏

Networking has a LOT of moving parts — cables, IP addresses, TCP, HTTP, encryption. To keep sanity, engineers organize it into layers, each with one job, stacked on top of each other. The OSI model (7 layers) and the TCP/IP model (4 layers) are the two famous ways to slice it. This is the mental map for the whole series.

What we will cover:

  • Why we use layers at all
  • The 7 OSI layers (and a memory trick)
  • The 4-layer TCP/IP model (what's really used)
  • Encapsulation — how data wraps up
  • Where HTTP, TCP, IP live
  • Interview Questions

1. Why Layers? The Postal Analogy

   When you send a letter, different people handle different jobs:
     • YOU write the message      (you don't care about trucks)
     • the post office sorts it   (doesn't care what you wrote)
     • the truck driver delivers  (doesn't read addresses)

   Each layer does ONE job and trusts the others. You can swap the
   truck for a plane without rewriting your letter.

   Networking layers work the same way: each layer has one job and
   talks only to the layers directly above and below it. Change WiFi
   to ethernet? The HTTP layer never notices. This SEPARATION is
   what makes networking manageable.

2. The 7 OSI Layers

┌───────────────────────────────────────────────────────────────┐
│  LAYER 7  APPLICATION  → what the user/app sees (HTTP, DNS)    │
│  LAYER 6  PRESENTATION → format, encrypt, compress (TLS, JPEG) │
│  LAYER 5  SESSION      → open/manage/close conversations       │
│  LAYER 4  TRANSPORT    → reliable delivery, ports (TCP, UDP)   │
│  LAYER 3  NETWORK      → routing between networks, IPs (IP)    │
│  LAYER 2  DATA LINK    → local delivery, MAC addresses (Eth)   │
│  LAYER 1  PHYSICAL     → the raw bits on wire/wifi (cables)    │
└───────────────────────────────────────────────────────────────┘

   MEMORY TRICK (top→bottom):
   "All People Seem To Need Data Processing"
    A   P     S    T   N    D     P

Data flows down the layers on the sender (app → wire) and up on the receiver (wire → app).


3. The TCP/IP Model (What's Actually Used)

OSI is the teaching model. The real internet runs on the simpler 4-layer TCP/IP model. It merges some OSI layers:

   TCP/IP (4 layers)          ≈  OSI layers
   ───────────────────           ─────────────
   APPLICATION   (HTTP, DNS)  ≈  7 + 6 + 5
   TRANSPORT     (TCP, UDP)   ≈  4
   INTERNET      (IP)         ≈  3
   NETWORK ACCESS(Ethernet)   ≈  2 + 1

   Same ideas, fewer boxes. Interviewers accept either model —
   just know which layer each protocol lives in.

4. Encapsulation — How Data Wraps Up

As data goes down the layers, each layer wraps it in its own header — like putting a letter in envelopes within envelopes.

   You send "Hello" over HTTP:

   App:       [ HTTP: Hello ]
   Transport: [ TCP hdr | HTTP: Hello ]          ← adds ports, seq#
   Internet:  [ IP hdr | TCP hdr | HTTP: Hello ] ← adds src/dst IP
   Link:      [ Eth hdr | IP hdr | TCP hdr | Hello | Eth trailer ]
                                                  ← adds MAC address

   Each layer adds its OWN header (encapsulation). At the receiver,
   each layer PEELS its header off (decapsulation) on the way up.
   Layer N on the sender talks to Layer N on the receiver.

5. Where the Famous Protocols Live

Layer (TCP/IP)JobProtocols / Units
ApplicationApp-level dataHTTP, HTTPS, DNS, FTP, SMTP
TransportProcess-to-process, reliability, portsTCP, UDP (unit: segment)
InternetHost-to-host routing across networksIP, ICMP (unit: packet)
Network AccessLocal hop on physical mediumEthernet, WiFi, MAC (unit: frame)

Interview gold: "HTTP is Application layer, TCP is Transport, IP is Internet/Network, Ethernet is Link. HTTP runs on top of TCP, which runs on top of IP."


Interview Questions — Quick Fire!

Q: Why do we use a layered network model?

"Layering separates networking into independent parts, each with a single responsibility that talks only to the layers directly above and below it. This modularity means you can change one layer — say switch from WiFi to Ethernet — without affecting the others, like HTTP. It simplifies design, troubleshooting, and lets different technologies interoperate through standard interfaces."

Q: What are the layers of the OSI model?

"From top to bottom: Application, Presentation, Session, Transport, Network, Data Link, and Physical. The Application layer is what apps use like HTTP; Transport handles reliable delivery and ports with TCP and UDP; Network handles routing with IP; Data Link handles local delivery with MAC addresses; and Physical is the raw bits on the wire. A common mnemonic is 'All People Seem To Need Data Processing.'"

Q: What's the difference between the OSI and TCP/IP models?

"OSI has seven layers and is mainly a conceptual teaching model, while the TCP/IP model has four layers and reflects how the internet actually works. TCP/IP merges OSI's top three layers into one Application layer and its bottom two into a Network Access layer. Both describe the same concepts; TCP/IP is just more practical."

Q: What is encapsulation?

"Encapsulation is how data is wrapped as it moves down the layers: each layer adds its own header, and sometimes a trailer, containing that layer's control information — ports at the transport layer, IP addresses at the network layer, MAC addresses at the link layer. At the receiver, each layer removes its corresponding header on the way up. It's like putting a letter inside nested envelopes."

Q: Which layer does HTTP, TCP, and IP belong to?

"HTTP is at the Application layer, TCP is at the Transport layer, and IP is at the Network or Internet layer. They stack: HTTP runs on top of TCP, which runs on top of IP. So an HTTP request is carried in TCP segments, which are carried in IP packets across the network."


Key Points to Remember

ConceptKey Takeaway
Why layersEach layer = one job; swap one without breaking others.
OSI7 layers (App→Physical). Teaching model. "All People Seem To Need Data Processing."
TCP/IP4 layers (App, Transport, Internet, Network Access). What's actually used.
EncapsulationEach layer adds its own header going down; peels it off going up.
Protocol homesHTTP=App · TCP/UDP=Transport · IP=Internet · Ethernet=Link.

What's Next?

Chapter 03 zooms into the Network layer's star: the IP address. IPv4 vs IPv6, public vs private, and what a "subnet" actually means.

Keep learning, keep connecting! See you in the next one!