Why layers
Networking is hard because it does many jobs at once. When your laptop calls kade-api, something has to:
| Job | Solved in | |
|---|---|---|
| 1 | Say what the app wants: "GET /profile" | HTTP (chapter 1) |
| 2 | Reach the right program on the server, reliably and in order | TCP and ports (coming) |
| 3 | Find a way across many networks | IP, routing (chapters 2-6) |
| 4 | Get across one local link, as signals | MAC, ARP, WiFi (chapters 7-9) |
Layering splits these jobs apart. Each job is handled by one layer, and each layer only talks to the layer directly above and below it.
The TCP/IP model: 4 layers
The model the internet actually runs on is the TCP/IP model. Top to bottom:
| Layer | Job | Protocols | Address used | Unit of data |
|---|---|---|---|---|
| 4 · Application | What your program speaks | HTTP, DNS, TLS, SSH | names, URLs | message |
| 3 · Transport | App-to-app delivery | TCP (reliable), UDP (fast) | ports | segment (TCP), datagram (UDP) |
| 2 · Internet | Routing across networks | IP, ICMP | IP addresses | packet |
| 1 · Link | One local hop, as signals | Ethernet, WiFi, ARP | MAC addresses | frame |
The OSI model: 7 layers
The OSI model is the classic teaching model. It splits the top and bottom of TCP/IP into finer pieces:
| # | Layer | Job | Examples | Unit |
|---|---|---|---|---|
| 7 | Application | Network services an app uses | HTTP, DNS, SSH | data |
| 6 | Presentation | Format of the data: encoding, encryption, compression | UTF-8, JSON, gzip, TLS (partly) | data |
| 5 | Session | Opening, keeping and closing a conversation | login sessions, TLS session resumption | data |
| 4 | Transport | App-to-app delivery | TCP, UDP | segment / datagram |
| 3 | Network | Routing across networks | IP, ICMP, routers | packet |
| 2 | Data link | Delivery on one local link | Ethernet, WiFi, MAC, switches | frame |
| 1 | Physical | Bits as signals | cables, radio, light, the NIC's transmitter | bits |
How the two line up
The models are not rivals. They describe the same stack at different levels of detail:
Wide by design - scroll it sideways.
- OSI's top three (Application, Presentation, Session) → TCP/IP Application.
- OSI Transport → TCP/IP Transport. OSI Network → TCP/IP Internet.
- OSI's bottom two (Data link, Physical) → TCP/IP Link.
Layer numbers in everyday talk
When people say "layer N", they mean the OSI number. Here is what the common phrases mean, with Kadé examples:
| # | You hear | It means | Kadé example |
|---|---|---|---|
| 2 | "a layer-2 switch" | Moves frames by MAC address inside one network | The staff network's switch (chapter 6) |
| 3 | "a layer-3 device" | Routes packets by IP address between networks | The office router |
| 4 | "a layer-4 load balancer" | Spreads connections using only IP and port; never reads HTTP | A GCP passthrough network load balancer |
| 7 | "a layer-7 proxy" | Reads the HTTP request (path, headers) to decide | A GCP application load balancer sending /api/* to kade-api |
| 3/4 | "a layer-3/4 firewall" | Allows or blocks by IP, protocol and port | GCP VPC firewall rules: only kade-api to kade-db on 5432 |
| 7 | "a WAF" | Web application firewall: inspects HTTP content | Cloudflare or Cloud Armor blocking bad requests |
Layers explain encapsulation
Chapter 1's three envelopes were the layers at work. Going down the stack, each layer wraps what it got from above in its own header. At the receiver, each layer removes its own header and passes the rest up.
Wide by design - scroll it sideways.
| Layer | Adds | Result is called |
|---|---|---|
| Application | the HTTP request itself | message (data) |
| Transport | TCP or UDP header: ports, sequence number | segment / datagram |
| Internet | IP header: source and destination IP, TTL | packet |
| Link | frame header and trailer: MACs, FCS | frame |
| (Physical) | nothing: turned into signals | bits |
Remembering the OSI order
Bottom → top (1 to 7)
Please Do Not Throw Sausage Pizza Away
Physical, Data link, Network, Transport, Session, Presentation, Application
Top → bottom (7 to 1)
All People Seem To Need Data Processing
Application, Presentation, Session, Transport, Network, Data link, Physical
The model as a filing system
When you meet a new protocol, ask "what layer is this?" and you immediately know its job. Test yourself, including a few tricky ones:
- HTTP
- TCP
- IP
- Ethernet
- DNS
- UDP
- ICMP
- ARP
- TLS
- DHCP
- BGP
- WiFi
- SSH
- NAT
Score: 0 / 0 answered, of 14.
Debugging layer by layer
Layers also give you a debugging order. When "kade-api is down" from the office, check from the bottom up. Each step only makes sense once the one below it works:
| # | Layer | Question | Command | If it fails |
|---|---|---|---|---|
| 1 | Link | Am I connected to the local network? | ip link, arp -a | Cable, WiFi or switch problem. Gateway MAC missing. |
| 2 | Internet | Can packets get there? | ping 172.16.1.1, ping 1.1.1.1, traceroute | Routing, gateway or ISP problem (chapters 5, 12, 13) |
| 3 | Transport | Is the port open? | nc -vz api.kade.lk 443 | Firewall rule, or the app is not listening |
| 4 | Application | Does the app answer correctly? | dig api.kade.lk, curl -v https://api.kade.lk/health | DNS, TLS certificate or app bug |
Summary
| # | Idea | In one line | New terms |
|---|---|---|---|
| 1 | Layering | One job per layer; each talks only to its neighbours | layer |
| 2 | TCP/IP | Application, Transport, Internet, Link: what the internet runs | TCP/IP model |
| 3 | OSI | 7 layers for teaching and talking; 5 and 6 rarely separate | OSI model |
| 4 | Mapping | OSI 7-5 → Application, 4 → Transport, 3 → Internet, 2-1 → Link | |
| 5 | Talk | "L4" = IP + port only; "L7" = reads HTTP | L4 / L7 |
| 6 | Encapsulation | Wrap going down, unwrap going up; routers stop at the Internet layer | segment, datagram, packet, frame |
| 8 | Filing | Know the layer, know the job | |
| 9 | Debugging | Check bottom-up: link, IP, port, app |
Try it yourself
Three packets, all layers at once
- What to look for:
-eadds the MACs (link), then IPs (internet), then ports and TCP flags (transport). - Runs on: macOS (Linux: -i wlan0 or eth0)
- From section: 6. Layers explain encapsulation
sudo tcpdump -e -n -c 3 -i en0 port 443The same, as a tree
- Steps: Wireshark
- What to look for: Click one packet: Frame → Ethernet → IP → TCP → TLS/HTTP, one layer per line.
- From section: 6. Layers explain encapsulation
A transport-layer check
- What to look for: "succeeded" means the port is open, without speaking HTTP at all.
- Runs on: any host and port
- From section: 9. Debugging layer by layer
nc -vz api.kade.lk 443An application-layer check
- What to look for: Lines starting with
*show TCP and TLS;>and<show HTTP. - From section: 9. Debugging layer by layer
curl -v https://example.com