OSI & TCP/IP Models

The 7-layer OSI model and the 4-layer TCP/IP model, what each layer does, encapsulation, and which protocols and devices live where.

Beginner 4 min readLesson 2 of 15 Interview Q&A

Networking is split into layers so each problem can be solved independently: how to send bits over a wire, how to deliver a frame to the next device, how to route across the world, how to make delivery reliable, and what the application actually says. Each layer offers a service to the layer above and uses the layer below.

The two models

7 ApplicationHTTP, DNS, SMTP, SSHApplication6 Presentationencoding, encryption (TLS-ish)Application5 Sessionsessions, dialogue controlApplication4 TransportTCP, UDP, QUIC — portsTransport3 NetworkIP, ICMP — routing between networksInternet2 Data linkEthernet, Wi-Fi — MAC addresses, framesLink1 Physicalcables, radio, voltages, lightLink

The OSI model (7 layers) is the standard vocabulary — engineers say "a layer 7 load balancer" or "a layer 2 switch". The TCP/IP model (4 layers) is what the Internet actually implements. OSI's session and presentation layers don't exist as separate protocols in practice; their jobs are done by applications and TLS.

What each layer does

LayerUnit of dataAddressingJobDevices
Application (7)MessageURLs, hostnamesWhat the program means: request a page, send an email—
Transport (4)Segment (TCP) / datagram (UDP)PortsDeliver between processes; reliability, ordering, flow and congestion control (TCP)Firewalls, L4 load balancers
Network (3)PacketIP addressesDeliver between hosts across networks; routingRouters
Data link (2)FrameMAC addressesDeliver to the next device on the same link; error detectionSwitches, access points
Physical (1)Bits—Signals on the mediumCables, hubs, repeaters, radios

Encapsulation

Going down the stack, each layer wraps the data from above with its own header (and the link layer adds a trailer too). Going up at the receiver, each layer strips its header and passes the payload up.

HTTP requestTCP hdrHTTP requestIP hdrTCP hdrHTTP requestEth hdrIP hdrTCP hdrHTTP requestFCS
Segment → packet → frame. Routers look only up to the IP header; switches only at the Ethernet header.

Typical overhead: Ethernet 14 bytes + 4-byte trailer, IPv4 20 bytes, TCP 20 bytes (more with options). With a 1500-byte MTU (maximum transmission unit), that leaves about 1460 bytes of application data per packet — the MSS (maximum segment size).

Where common things live

ThingLayer
HTTP, DNS, SMTP, SSH, gRPC, WebSocket7
TLSBetween 4 and 7 (often called 6, or "layer 4.5")
TCP, UDP, QUIC (over UDP)4
IP, ICMP (ping), IPsec3
ARP (IP → MAC lookup)Between 2 and 3
Ethernet, Wi-Fi (802.11), VLANs2
Fibre, copper, radio1
L4 load balancer (by IP and port)4
L7 load balancer / API gateway (by URL path, headers)7

Why layering matters in practice

  • Independence — HTTP works the same over Wi-Fi, Ethernet or 5G; TCP doesn't care whether the link is fibre or radio.
  • Debugging — work bottom-up: is the link up (1/2)? Is there an IP and a route (3)? Is the port open (4)? Is the application responding correctly (7)?
  • Vocabulary — "it's a layer 7 problem" means the network is fine and the application isn't.
Key takeaways
  • OSI has 7 layers (vocabulary); TCP/IP has 4 (implementation).
  • Transport delivers between processes (ports); network between hosts (IP); link between neighbours (MAC).
  • Data units: frame (L2), packet (L3), segment/datagram (L4).
  • Encapsulation wraps each layer's header around the payload from above.
  • Debug bottom-up through the layers.
Interview questions
QAt which layers do a switch, a router and a load balancer operate?easy

A switch at layer 2 (MAC addresses), a router at layer 3 (IP addresses). A load balancer at layer 4 (IP and port, forwarding TCP/UDP connections) or layer 7 (understanding HTTP and routing by path, host or headers).