Loading a web page means solving several unrelated problems at once. Bits have to travel over a cable or a radio wave. The data has to find one machine among billions. Pieces lost along the way have to be sent again. And the browser and the server have to agree on what the bytes mean. Networks handle this by splitting the work into layers, where each layer solves one problem and relies on the layer below it for the rest.
A layer only talks to the layers directly above and below it on the same machine, and to its matching layer on the other machine. That separation is the point. A browser does not care whether data crosses Wi-Fi or a cable, and the Wi-Fi hardware does not care whether it is carrying a web page or an email. Either side can change without touching the other.
Two models describe these layers. TCP/IP has four layers and matches the protocols the internet actually runs. The OSI model has seven and cuts the same stack more finely. It is easiest to start with the practical one.
The four TCP/IP layers
TCP/IP, described in RFC 1122, has four layers. From the top:
| Layer | Job | Address it uses | Data unit | Examples |
|---|---|---|---|---|
| Application | Defines what two programs say to each other | Domain names | Message | HTTP, DNS, SMTP, SSH |
| Transport | Delivers data to the right program | Port number | Segment (TCP) or datagram (UDP) | TCP, UDP |
| Internet | Routes data between networks | IP address | Packet | IP, ICMP |
| Link | Moves data across one local network | MAC address | Frame | Ethernet, Wi-Fi |
Each layer has its own kind of address, and delivering a message to the right program takes all three. A MAC address identifies a network card on the local network. An IP address identifies a machine across networks. A port number identifies a program on that machine. The link layer gets data to the next device, the internet layer gets it to the right machine, and the transport layer gets it to the right program.
The internet layer is best-effort: IP can lose, duplicate, or reorder packets without telling anyone. TCP fixes this by numbering the data, having the receiver acknowledge what arrived, and re-sending what did not. UDP skips all of that. It is lighter and faster, which suits things like DNS lookups and live video, where a late packet is worse than a missing one.
The seven OSI layers
The OSI model was published as an ISO standard in 1984. The diagram shows how its seven layers line up with the four above.
The two models agree in the middle and differ at the edges. OSI’s network and transport layers (3 and 4) match TCP/IP’s internet and transport layers directly. At the top, TCP/IP’s single application layer is three layers in OSI: application (the protocols programs use to talk, such as HTTP), presentation (how data is represented, compressed, or encrypted), and session (starting, maintaining, and ending a conversation). At the bottom, OSI separates the data link layer, which handles frames and MAC addresses, from the physical layer, which turns bits into voltage, light, or radio signals. Some textbooks teach a five-layer version of TCP/IP that makes the same split.
OSI was designed as a reference model, and the internet ended up running on TCP/IP instead. As a result, real protocols do not always fit OSI’s upper layers. TLS, for example, encrypts data like a presentation-layer job and sets up a secure session like a session-layer job, yet in TCP/IP it simply runs as part of the application layer on top of TCP. What survives of the seven-layer model is its numbering, used as shared vocabulary: a “layer 2 switch” forwards frames by MAC address, a “layer 3 device” such as a router works with IP addresses, and a “layer 7 load balancer” makes decisions based on the content of HTTP requests.
Following one web request
Say you type example.com into a browser and press Enter. The browser first asks DNS, another application-layer protocol, to turn the name into an IP address. It then opens a TCP connection to the server and sends an HTTP request. Each layer wraps what it receives from above in its own header, a block of control information placed in front of the data. This is called encapsulation.
Working from the inside out:
- The application layer produces the HTTP request, such as
GET /index.html. - The transport layer adds a source port and a destination port (443 for HTTPS), plus sequence numbers so the receiver can put the pieces back in order and acknowledge them.
- The internet layer adds the source IP address (yours) and the destination IP address (the server’s).
- The link layer adds MAC addresses and a trailer containing an error check, then sends the frame out as signals.
One detail trips people up: the destination MAC address in that frame is not the server’s. It belongs to the next device on the path, usually your home router. IP addresses stay the same from end to end, but MAC addresses change at every hop.
When the frame reaches the router, the router removes the link layer and reads the destination IP address in the packet. It decides which neighbor is closest to that destination, builds a new frame addressed to that neighbor’s MAC address, and transmits it. A router only needs the IP header to do this, so it never has to open the TCP segment or the HTTP data, and the diagram shows it with two layers. A packet usually crosses several routers this way. With HTTPS, the HTTP request is also encrypted by TLS before it reaches TCP, so the devices along the path can see addresses and ports but not the contents.
At the server, the process runs in reverse. The link layer checks the frame and strips it off, the internet layer confirms the packet is addressed to this machine, and the transport layer reassembles the segments in order and uses the destination port to hand the data to the web server program listening on port 443. The response travels back the same way, with source and destination swapped.
Related articles in Technical Explainers
- Document Databases and JSON Data Modeling — Understand nested documents, indexes, embedding, and references.