# How the Internet Works: OSI and TCP/IP

> Understand the layered models of networking, what each layer is responsible for, and how a packet is encapsulated from your app down to the wire and back. Free...

Canonical: https://www.internhack.in/roadmaps/tracks/cs-fundamentals/network-models
Last updated: 2026-11-28

Understand the layered models of networking, what each layer is responsible for, and how a packet is encapsulated from your app down to the wire and back.

Beginner · about 5 hours · difficulty 2/5

Networking is easiest to learn as a stack of layers, each solving one problem and relying on the one below. Interviewers use the models as a map, so you should be able to place any protocol or device on it.

### The two models

- **OSI (7 layers)**: Physical, Data Link, Network, Transport, Session, Presentation, Application. A teaching model.
- **TCP/IP (4 or 5 layers)**: Link, Internet (IP), Transport (TCP/UDP), Application (HTTP, DNS, SMTP). This is what the real internet runs on.

### What each layer does

- **Physical**: bits on copper, fibre or radio.
- **Data link**: frames between directly connected machines, **MAC addresses**, error detection (CRC), switches, Ethernet, Wi-Fi.
- **Network**: routing packets across networks with **IP addresses**; routers live here.
- **Transport**: process-to-process delivery using **ports**; reliability (TCP) or speed (UDP).
- **Application**: the protocols your software speaks.

### Encapsulation

Your HTTP request becomes a TCP segment (adds ports), then an IP packet (adds IPs), then an Ethernet frame (adds MACs). Each hop's router strips the frame, reads the IP header, and re-frames it for the next link. **ARP** resolves an IP to a MAC on the local network.

### Devices and terms

Hub (layer 1), switch (layer 2), router (layer 3), and gateway; LAN vs WAN; bandwidth vs latency vs throughput; circuit vs packet switching.

Good enough to move on: you can narrate, layer by layer, what happens when you type a URL and press Enter, which is one of the most common networking interview questions.

## Key concepts

- **OSI model layers**
- **TCP/IP model**
- **Encapsulation and headers**
- **MAC addresses and ARP**
- **Hubs, switches and routers**
- **Bandwidth, latency, throughput**
- **What happens when you type a URL**

## Mini project

Capture your own traffic with Wireshark while loading a website and annotate one request through every layer: Ethernet frame, IP header, TCP segment and HTTP payload, noting source and destination at each level.

## Check yourself

When a packet crosses three routers to reach a server, which addresses change at each hop and which stay the same?

## Free resources

- [Computer Networking: A Top-Down Approach (author resources)](https://gaia.cs.umass.edu/kurose_ross/index.php) (Kurose and Ross)
- [MDN: How does the Internet work?](https://developer.mozilla.org/en-US/docs/Learn_web_development/Howto/Web_mechanics/How_does_the_Internet_work) (MDN)
- [Cloudflare Learning Center: What is the OSI model?](https://www.cloudflare.com/learning/ddos/glossary/open-systems-interconnection-model-osi/) (Cloudflare)

Previous: [File Systems, Storage and I/O](https://www.internhack.in/roadmaps/tracks/cs-fundamentals/file-systems-and-io) · Next: [IP Addressing, Subnetting and Routing](https://www.internhack.in/roadmaps/tracks/cs-fundamentals/ip-addressing-routing)

## More in Computer Networks

- [How the Internet Works: OSI and TCP/IP](https://www.internhack.in/roadmaps/tracks/cs-fundamentals/network-models)
- [IP Addressing, Subnetting and Routing](https://www.internhack.in/roadmaps/tracks/cs-fundamentals/ip-addressing-routing)
- [Transport Layer: TCP and UDP](https://www.internhack.in/roadmaps/tracks/cs-fundamentals/tcp-and-udp)
- [DNS](https://www.internhack.in/roadmaps/tracks/cs-fundamentals/dns)
- [HTTP, HTTPS and TLS](https://www.internhack.in/roadmaps/tracks/cs-fundamentals/http-and-https)
- [Network Security Essentials](https://www.internhack.in/roadmaps/tracks/cs-fundamentals/network-security-basics)

## Related

- [Roadmaps](https://www.internhack.in/roadmaps)
- [CS Fundamentals and Placement Prep Roadmap](https://www.internhack.in/roadmaps/tracks/cs-fundamentals)
