Sub topic 2
The OSI Reference Model: Seven Layers
This chapter assumes you know what a client and a server are, have used a network, and can run commands in a terminal. It describes the OSI model, the seven-layer reference model used as a shared vocabulary for networking. The TCP/IP model and the mapping between the two come in later chapters.
What the OSI model is
OSI stands for Open Systems Interconnection. The International Organization for Standardization (ISO) published it as a reference model: a way to divide communication into parts, not a protocol you install. Each layer has one job. It uses the services of the layer below and offers services to the layer above.
Engineers still use the layer numbers in daily speech. "A layer 2 problem" means a problem with local delivery, such as Ethernet or MAC addresses. "A layer 7 load balancer" means one that reads application data such as HTTP headers.
The seven layers
Layers are numbered from the bottom up. Layer 1 is closest to the wire, and layer 7 is closest to the application.
| Layer | Name | Job | Example protocols or items |
|---|---|---|---|
| 7 | Application | Services that network applications use directly | HTTP, DNS, SMTP |
| 6 | Presentation | Data format, encoding, compression, encryption | TLS (loosely), JPEG, character encodings |
| 5 | Session | Starting, managing, and ending a dialogue between two ends | RPC session handling, NetBIOS |
| 4 | Transport | End-to-end delivery between processes, using ports | TCP, UDP |
| 3 | Network | Addressing and routing between networks | IP, ICMP |
| 2 | Data link | Delivery between devices on the same link | Ethernet, Wi-Fi, ARP |
| 1 | Physical | Moving raw bits as signals | Copper cable, fiber, radio |
A common memory aid for layers 7 to 1 is "All People Seem To Need Data Processing."
Layers 1 and 2: getting bits across one link
The physical layer defines voltages, light pulses, radio frequencies, connectors, and cable types. It knows nothing about the meaning of the bits.
The data link layer groups bits into frames and delivers them to another device on the same local network. It uses hardware addresses (MAC addresses) and detects transmission errors with a checksum. A switch works mainly at this layer.
Layer 3: getting packets across networks
The network layer gives every host a logical address and chooses a path through many networks. A router works at this layer. IP is the main protocol here. It delivers on a best-effort basis, which means it does not promise that a packet arrives.
Layer 4: getting data to the right process
The transport layer connects one program on one host to one program on another. Ports identify the programs. TCP adds reliability, ordering, and flow control. UDP adds only ports and an optional checksum.
Layers 5 to 7: what the data means
The session layer manages the dialogue. The presentation layer handles how data is represented. The application layer is where protocols such as HTTP and DNS define the messages themselves. In real TCP/IP software these three layers are usually a single piece of application code, which is why the TCP/IP model merges them. The next chapter covers that.
How the layers cooperate
Each layer talks to the same layer on the other machine through a protocol, and it talks to its neighbors through an interface. The sender's layer 4 adds information that only the receiver's layer 4 reads. The layers below carry that information without examining it.
Common mistakes
- Treating OSI as a description of how the internet is built. The internet's protocols were designed around TCP/IP, and OSI was written as a reference model alongside it.
- Forcing every protocol into exactly one layer. Some protocols, such as ARP and TLS, do not fit neatly. A later chapter covers these cases.
- Looking for separate session and presentation code in a typical program. In most TCP/IP applications this work happens inside the application protocol or a library.
Exercise
A switch forwards Ethernet frames using MAC addresses, and a router forwards packets using IP addresses. At which OSI layer does each device mainly work?
Show answer
The switch works mainly at layer 2 (data link), because MAC addresses and frames belong to that layer. The router works at layer 3 (network), because IP addresses and packets belong to that layer.
Exercise
Which OSI layer does a port number belong to, and what does it identify?
Show answer
A port number belongs to layer 4 (transport). It identifies which program on a host should receive the data.