Notes › Computer Networks
OSI and TCP/IP Models
Networking is split into layers. Each layer does one job and only talks to the layers directly above and below it. This makes the system modular: Wi-Fi can be replaced by Ethernet without changing HTTP.
The OSI model (7 layers)
| # | Layer | Job | Protocols / examples | Data unit | Devices |
|---|---|---|---|---|---|
| 7 | Application | services for user apps | HTTP, HTTPS, FTP, SMTP, DNS, SSH | data | — |
| 6 | Presentation | format, encryption, compression | TLS/SSL, JPEG, UTF-8, gzip | data | — |
| 5 | Session | open, manage and close sessions; checkpoints | RPC, NetBIOS, session tokens | data | — |
| 4 | Transport | process-to-process delivery, ports, reliability, flow control | TCP, UDP | segment (TCP) / datagram (UDP) | firewall (L4), load balancer (L4) |
| 3 | Network | logical (IP) addressing and routing across networks | IP, ICMP, ARP*, OSPF, BGP | packet | router, L3 switch |
| 2 | Data Link | node-to-node delivery on one link, MAC addresses, error detection | Ethernet, Wi-Fi (802.11), PPP | frame | switch, bridge, NIC |
| 1 | Physical | raw bits over the medium | cables, fibre, radio, voltages | bits | hub, repeater, cables |
*ARP sits between layers 2 and 3 (it maps IP → MAC).
Mnemonics
- Top → bottom: All People Seem To Need Data Processing.
- Bottom → top: Please Do Not Throw Sausage Pizza Away.
The TCP/IP model (what the internet actually uses)
| TCP/IP layer | OSI layers it covers | Protocols |
|---|---|---|
| Application | 7, 6, 5 | HTTP, DNS, SMTP, FTP, TLS |
| Transport | 4 | TCP, UDP |
| Internet | 3 | IP, ICMP |
| Network Access (Link) | 2, 1 | Ethernet, Wi-Fi |
(Some books split the last one into Data Link + Physical → a 5-layer model.)
OSI vs TCP/IP
| OSI | TCP/IP | |
|---|---|---|
| Layers | 7 | 4 (or 5) |
| Nature | reference/teaching model | practical model used on the internet |
| Developed | protocols-independent, model first | protocols first, model described later |
| Session & presentation | separate layers | folded into Application |
Encapsulation — what happens when you send data
Each layer adds its own header (Data Link also adds a trailer) as data moves down on the sender; the receiver strips them going up.
Application [ HTTP data ]
Transport [ TCP hdr | HTTP data ] ← segment (ports 52314 → 443)
Network [ IP hdr | TCP hdr | data ] ← packet (IPs)
Data Link [ Eth hdr | IP hdr | TCP hdr | data | FCS ] ← frame (MACs, checksum)
Physical 0101011010… ← bits
- MAC address (48-bit, e.g.
3C:52:82:1A:9F:04) changes at every hop — it's for the next device on the link. - IP address stays the same from source to destination (except with NAT).
- Port identifies the application on the host (443 = HTTPS, 22 = SSH).
Devices and layers
| Device | Layer | Works with |
|---|---|---|
| Hub / repeater | 1 | bits — sends to every port |
| Switch | 2 | MAC addresses — sends only to the right port |
| Router | 3 | IP addresses — connects different networks |
| Gateway / proxy / L7 load balancer | 7 | full application data |
See Network Devices and Common Ports.
Which layer is the problem? (troubleshooting)
- Cable unplugged, no link light → Physical.
- Same Wi-Fi but devices can't see each other → Data Link.
ping 8.8.8.8fails → Network (IP/routing).- Ping works but the port is blocked → Transport (firewall).
ping google.comfails butping 8.8.8.8works → DNS (Application).- Site loads but shows an error → Application.
Interview one-liners
- 7 OSI layers: Physical, Data Link, Network, Transport, Session, Presentation, Application.
- Data units: bits → frames → packets → segments → data.
- Switch = layer 2 (MAC); router = layer 3 (IP).
- TCP/IP has 4 layers; OSI is the reference model, TCP/IP is what's implemented.
- TLS is usually placed at the Presentation layer (OSI) / Application layer (TCP/IP).
- Related: TCP vs UDP and the 3-Way Handshake, What Happens When You Type a URL.