Sub topic 11
OSI versus the TCP/IP model
This chapter assumes you know the seven OSI layers and their jobs, and that you understand encapsulation. You should also be comfortable with terms like IP address, port, and frame.
Two models, two purposes
The OSI model is a reference model. It was written to describe any network protocol suite in seven layers, and it is mostly used for teaching and for naming problems.
The TCP/IP model describes the protocols the internet actually runs. It grew out of working protocols (IP, TCP, UDP) rather than the other way around. Its layers are drawn around those protocols, so there are fewer of them.
Most documents use the four-layer version (Link, Internet, Transport, Application). Some textbooks split Link into Physical and Data Link, which gives five layers. This chapter uses four.
How the layers line up
| OSI layer | TCP/IP layer | Typical protocols |
|---|---|---|
| 7 Application, 6 Presentation, 5 Session | Application | HTTP, DNS, SMTP, TLS, SSH |
| 4 Transport | Transport | TCP, UDP |
| 3 Network | Internet | IP, ICMP |
| 2 Data Link, 1 Physical | Link | Ethernet, Wi-Fi, ARP |
The mapping is approximate. It is a convenient comparison, not an exact equivalence, because the two models were not designed to match.
Where they differ
Top three layers collapse into one
TCP/IP has no separate session or presentation layer. The application itself, or a library it uses, handles those jobs. A web browser handles character encoding, and a TLS library encrypts the data. HTTP cookies and connection reuse play the role of session management.
This is why people argue about where TLS belongs. It encrypts data (a Layer 6 job), yet it runs over TCP and is started by the application. In TCP/IP terms the question does not come up: TLS is part of the Application layer.
import socket
import ssl
context = ssl.create_default_context()
with socket.create_connection(("example.com", 443), timeout=5) as raw:
# Encryption is added by the application's library, on top of TCP.
with context.wrap_socket(raw, server_hostname="example.com") as tls:
print(tls.version())The program never talks to a separate "presentation layer". It wraps a TCP socket with a library, so one process covers Layers 5 to 7.
Layer 1 and 2 merge
TCP/IP does not specify how bits travel on a wire or how frames are built. It only requires some link technology that can carry IP packets. Ethernet, Wi-Fi, and a PPP link all qualify.
Strict layering versus practical layering
OSI treats layers as strictly separate, with each one using only the layer directly below. TCP/IP is looser. Some real protocols cross boundaries. For example, TCP computes its checksum over a pseudo-header that includes IP addresses, so the Transport layer depends on Internet-layer fields. ARP carries IP addresses inside a Layer 2 frame and does not fit cleanly into either layer.
Protocols first versus model first
OSI was designed as a model, and its matching protocols saw little use. TCP/IP started as working protocols, and the model was written afterward to describe them. That is why the internet runs TCP/IP, while OSI terms survive as vocabulary.
Which one to use
Use OSI numbers when talking to other engineers. "A Layer 2 loop," "a Layer 4 load balancer," and "a Layer 7 firewall" are standard phrases. The numbers are shared shorthand even though the internet does not implement seven layers.
Use TCP/IP when you reason about real software. It matches how sockets, the kernel, and applications divide the work.
Common errors
- Treating the mapping table as exact. Protocols such as TLS, ARP, and MPLS do not sit neatly in one OSI layer.
- Assuming every product implements seven separate layers. Real stacks do not.
- Assuming "Layer 7" means only HTTP. It means anything above the transport layer, including DNS and SMTP.
- Mixing numbering schemes. "Layer 3" always means OSI Network. TCP/IP layers are usually named, not numbered, because five-layer and four-layer books number them differently.
Exercise
A colleague says "the TLS handshake is Layer 6, so TCP/IP has no place for it." Respond using both models.
Show answer
In OSI terms, TLS does Layer 6 work (encryption and encoding of data). TCP/IP has no separate Presentation layer, so TLS is part of the Application layer. It runs on top of TCP and is started by the application's library, as in the Python example above. The model is not missing anything. It just groups OSI Layers 5 to 7 together.
Exercise
Which TCP/IP layer covers OSI Layers 1 and 2, and what does TCP/IP require of it?
Show answer
The Link layer. TCP/IP only requires that the link technology can carry IP packets. It does not define how bits are signaled or how frames are formed, so Ethernet, Wi-Fi, and PPP can all be used.