OSI and TCP/IP Network Models
Compare the OSI and TCP/IP models, trace an HTTPS request through their layers, and use the models to narrow network failures without confusing abstractions.
OSI and TCP/IP offer different ways to describe where a network request may fail. This guide compares the models and follows HTTPS through DNS, routing, TCP, TLS, and HTTP, with examples such as timeouts, refused connections, and handshake errors. Use the checks to investigate one stage at a time, while treating the diagrams as guides rather than exact maps of every implementation.
OSI and TCP/IP Network Models
Introduction
When a request fails, the OSI and TCP/IP models give you a way to narrow the search. If DNS returns no address, changing the HTTP handler will not help; if TCP connects but TLS fails, the client has reached a later stage and the evidence points elsewhere.
This guide compares the two models, traces an HTTPS request through the stack, and uses resolver, route, socket, and TLS evidence to troubleshoot common failures. The models organize the investigation, while the actual protocol behavior tells you where to look next.
The seven OSI layers
The OSI model runs from the user’s data down to the physical medium, then back up at the destination:
| Layer | Name | What it describes | Familiar examples |
|---|---|---|---|
| 7 | Application | Network services used by applications | HTTP, DNS, SMTP |
| 6 | Presentation | Data representation, encoding, and transformations | Character encoding, serialization, encryption concepts |
| 5 | Session | Establishing and managing communication sessions | Session control concepts in application protocols |
| 4 | Transport | Process-to-process delivery, ports, reliability, and flow control | TCP, UDP |
| 3 | Network | Addressing and forwarding between networks | IP, routers |
| 2 | Data Link | Delivery on a local link and frame addressing | Ethernet, Wi-Fi link layer, switches |
| 1 | Physical | Signals and the medium carrying bits | Copper, fiber, radio |
Layers 5 and 6 are useful ways to discuss functions, but most Internet protocols do not appear as distinct protocol layers matching those boxes. For example, TLS handles encryption above TCP, but people sometimes describe its functions using OSI presentation-layer language. That is a conceptual comparison, not a claim that TLS is formally an OSI layer-6 protocol.
The Internet protocol suite
Many courses teach TCP/IP as a four-layer model:
| TCP/IP layer | Role | Examples |
|---|---|---|
| Application | Application protocols and their data formats | HTTP, DNS, SSH, SMTP |
| Transport | Communication between processes on hosts | TCP, UDP |
| Internet | Addressing and forwarding across interconnected networks | IPv4, IPv6, ICMP |
| Link | Communication over the local network technology | Ethernet, Wi-Fi |
Some diagrams split the Link layer into Data Link and Physical, producing a five-layer teaching model. Names and boundaries vary by textbook. The four-layer version groups the local-link and signaling functions together because Internet protocols can run over different link technologies.
How the models map
This is a useful approximate mapping:
| OSI | TCP/IP | Relationship |
|---|---|---|
| Application, Presentation, Session | Application | TCP/IP groups application protocols and functions that OSI discusses across three layers. |
| Transport | Transport | Both describe host-to-host process communication, though protocol details vary. |
| Network | Internet | Both cover logical addressing and forwarding between networks. |
| Data Link, Physical | Link | TCP/IP groups local delivery and the medium beneath it. |
The models answer slightly different questions. OSI is a reference model for discussing responsibilities. TCP/IP is a protocol suite with deployed protocols and a practical layering convention. A protocol may span functions that a reference model separates, and implementations do not always follow textbook boundaries neatly.
Trace an HTTPS request
Suppose a browser fetches https://api.example.com/orders. The operating system first needs an address for the hostname, commonly by using DNS. After resolving it, the client selects a route and sends traffic toward the server. A typical HTTP/1.1 or HTTP/2 connection then uses TLS over TCP.
Conceptually, the client builds the outgoing data like this:
- The application creates an HTTP request with a method, path, headers, and possibly a body.
- TLS encrypts the HTTP data and adds TLS record framing. This function is often compared with OSI presentation concerns, while still being part of the practical application-over-transport stack.
- TCP carries the encrypted byte stream between client and server ports. It handles sequencing, retransmission, and flow control.
- IP addresses the datagram and lets routers forward it between networks.
- Ethernet or Wi-Fi carries a frame across the current local link. At each routed hop, the link-layer frame is replaced for the next link; the end-to-end IP packet continues toward its destination, subject to routing and network translation.
- The receiving host processes the data in reverse, until its application can handle the HTTP request.
flowchart TD
A[HTTP request: application data] --> B[TLS records: encrypted application bytes]
B --> C[TCP segment: source and destination ports]
C --> D[IP datagram: source and destination addresses]
D --> E[Ethernet or Wi-Fi frame: local link delivery]
E --> F[Physical signals: bits on the medium]
F --> G[Router forwards IP datagram on the next link]
G --> H[Server receives and unwraps data]
This is a simplified picture. Segmentation, retransmission, fragmentation, tunnels, proxies, and offload features can change what a packet capture shows. The diagram explains responsibilities rather than promising one neat object per layer at every point in a real system.
When to Use
Use the models to describe where a symptom appears, to plan a troubleshooting sequence, or to explain how protocols depend on one another. For example, if DNS resolution fails, investigate the resolver path before debugging the HTTP handler. If TCP connects but the client receives an HTTP 503, the network path carried the request far enough for an application-level response.
When NOT to Use
Do not use the models as a rigid classification test. Real protocols can cross the boundaries in a diagram, and a single failure can involve several layers. Do not infer the cause from an OSI layer number alone. Gather evidence from the actual stack: resolver output, routes, socket state, packet captures, TLS logs, and application responses.
A practical diagnostic sequence
Replace api.example.com with the affected service. These Linux commands check name resolution, the selected route, an HTTPS attempt, and visible TCP sessions:
getent ahostsv4 api.example.com
ip route get 203.0.113.25
curl -sv --connect-timeout 5 https://api.example.com/ -o /dev/null
ss -tnp dst :443
203.0.113.25 is a documentation address, so substitute a real resolved address before running the route check. curl -v can reveal whether the client reached DNS, connected to TCP, negotiated TLS, and received an HTTP status. Redact authorization headers, cookies, and tokens before sharing verbose output. To inspect packets, capture only the required host and port with an approved packet-capture tool; payloads may contain sensitive metadata or unencrypted data.
Interpret results in sequence. No DNS answer points toward resolver configuration or DNS reachability. A missing route points toward local routing or interface configuration. A TCP timeout may come from filtering, a broken return path, or an unavailable destination; a refusal usually means a reachable host rejected the connection or nothing accepted that port. A completed TLS handshake followed by an HTTP error moves attention toward the proxy or application. See network ports and firewalls for listener binding and firewall checks.
Follow one failing request
Suppose one request to https://api.example.com/orders returns HTTP 503. That response shows TCP and TLS completed, but the status alone does not tell you whether the proxy, load balancer, or origin created the error. The layer label organizes the checks; logs and measurements help identify the faulty component.
$ curl -sv --connect-timeout 5 https://api.example.com/orders -o /dev/null
< HTTP/2 503
< x-request-id: req-example
This is illustrative output. For the same destination, check each boundary from the affected client:
For these commands, select one IPv4 address from DNS in the same shell:
TARGET_IP="$(getent ahostsv4 api.example.com | awk 'NR == 1 { print $1 }')"
| Boundary | Next diagnostic test | What the result tells you |
|---|---|---|
| Name resolution | Run getent ahosts api.example.com on the failing client and compare the returned addresses with a working client or the service’s expected records. |
A missing or unexpected address points to resolver configuration or stale service records. |
| Link and routing | Check ip -brief link, then run ip route get "$TARGET_IP". |
The interface state and selected route show whether the host has a path toward that address. Check the neighbor entry for the selected gateway if local delivery fails. |
| Transport | Run nc -vz -w 3 "$TARGET_IP" 443 from the same client network. |
A timeout or refusal on this separate probe conflicts with the successful curl result. Check whether conditions changed, then inspect the listener, firewall rules, and return path before changing policy. |
| TLS | Run openssl s_client -connect "$TARGET_IP:443" -servername api.example.com -verify_hostname api.example.com -verify_return_error -brief </dev/null. |
Check that the handshake completes and certificate verification succeeds for the requested hostname. Keep SNI set to that hostname. |
| HTTP | Repeat the request with curl -sv and retain the request ID. Compare that ID with reverse-proxy and upstream logs, then inspect upstream health and the source of the 503. |
Since the request returned 503 after TLS, compare its request ID with proxy and origin logs to find which component returned it. |
These probes make separate connections, so run them from the same network path and close to the time of the failure. If the affected client uses IPv6, set TARGET_IP to its resolved IPv6 address and bracket that address in the openssl -connect value. If an intermediate probe fails while the original request succeeds, compare the address family, destination IP, SNI, proxy settings, and timing before drawing a conclusion.
Production Failure Scenarios
DNS works on a laptop but fails in a container. The container may use a different resolver, search domain, or network policy. Compare resolver configuration and lookup results from the affected runtime, then monitor DNS errors separately from application failures.
TCP connects, but the HTTPS request hangs. The server may stop responding during TLS negotiation or after receiving the request. Compare client and server timestamps, inspect TLS and proxy logs, and capture handshake metadata where policy permits. Set connection and response timeouts so callers do not wait forever.
A service is reachable from one subnet but not another. Routes, security groups, network ACLs, or host firewall rules may differ. Check the effective path in both directions and validate from the failing source network. Avoid opening broad rules before identifying the boundary dropping traffic.
A deployment sends traffic to the wrong instance. Stale DNS records, an incorrect service-discovery entry, or a proxy pool can direct clients to an old address. Compare the resolved address with the intended deployment and attach instance identity to health and access logs.
A packet capture looks different from the textbook diagram. TCP segmentation offload and receive coalescing can make host captures show large segments that never appeared that way on the wire. Capture at another point or account for NIC offload before treating the capture as proof of malformed traffic.
Trade-Off Table
| Approach | Useful for | Cost or limitation |
|---|---|---|
| OSI seven-layer model | Precise discussion of responsibilities and teaching fundamentals | Can encourage false precision when real protocols cross boundaries |
| TCP/IP four-layer model | Relating common Internet protocols to deployed stacks | Groups several link functions and leaves fewer named boundaries |
| Five-layer teaching model | Separating local frame delivery from physical signaling | A teaching convention; not a separate deployed protocol suite |
| Layer-by-layer diagnosis | Keeping an incident investigation organized | Can become slow if teams check layers mechanically without following evidence |
Pick the model that makes the current conversation clearer, then name the concrete protocol or component under investigation.
Observability Checklist
- Record DNS lookup latency, failure rate, and resolver identity.
- Track connection attempts, TCP timeouts, refusals, retransmissions, and established socket counts.
- Measure TLS handshake failures separately from HTTP status codes and application latency.
- Include source, destination, protocol, port, and request or trace identifiers where safe.
- Correlate load balancer, firewall flow, host, proxy, and application logs by timestamp.
- Keep a known-good probe from each important network boundary; a probe from one subnet does not prove reachability from another.
- Set packet-capture scope and retention according to the incident need and data-handling policy.
Security and Compliance Notes
Encryption does not hide every network detail. IP addresses, ports, timing, packet sizes, and often DNS queries can remain visible to network observers, depending on the protocol and configuration. Use TLS for application data in transit, verify certificates, and avoid downgrading security to make a connection succeed.
Packet captures and verbose client traces may expose personal data, tokens, hostnames, or request metadata. Limit collection to the hosts and duration required, restrict access, redact secrets before attaching logs to tickets, and follow retention and regulatory requirements. Network segmentation and least-privilege firewall policy still matter when application traffic is encrypted.
Common Pitfalls / Anti-Patterns
- Treating the OSI and TCP/IP diagrams as exact translations instead of overlapping models.
- Calling every problem above Ethernet an “application-layer” issue, or blaming a single layer based on one symptom.
- Assuming that a successful ping proves an HTTPS service is reachable. ICMP handling and TCP port reachability are separate checks.
- Assuming a TCP connection proves TLS or HTTP works. Each handshake and response adds another boundary to inspect.
- Treating a port number as a protocol guarantee. Services can use nonstandard ports, and firewall rules do not identify application semantics.
- Forgetting that routing is bidirectional: a working outbound route does not guarantee a return path.
Quick Recap Checklist
- State whether you are using the OSI reference model or the TCP/IP model.
- Remember that OSI layers map approximately to TCP/IP layers, not one-to-one.
- Trace the request through DNS, route selection, transport, TLS, and application handling.
- Check both the outbound path and the return path.
- Use logs and measurements to confirm a layer hypothesis before changing production rules.
Interview Questions
- OSI is a reference model for responsibilities; deployed protocols do not always follow its boundaries.
- TCP/IP groups functions differently, and protocols such as TLS span concerns often associated with multiple OSI layers.
- Use the model to organize discussion, then name the protocol or component involved.
- The router removes the incoming link-layer frame and forwards the IP datagram according to its routing table.
- It sends the datagram in a new link-layer frame for the next hop.
- The end-to-end IP packet continues across the path, though routing or network translation can modify relevant fields.
- Check the selected route and test TCP reachability from the affected client network.
- Verify that the service is listening on the expected address and port.
- Inspect host and network firewall rules, security groups, and the return path before changing policy.
- Compare results from a working network boundary to isolate where behavior differs.
- TCP segmentation offload can let the host stack pass a large buffer to the NIC for segmentation.
- Receive coalescing can combine segments before the capture point sees them.
- Check capture location and NIC offload settings before treating the host capture as an on-wire packet trace.
Further Reading
- Network ports and firewalls explains listeners, routes, and firewall boundaries in deployment troubleshooting.
- TCP, IP, and UDP explains the protocols that sit within the layered models.
- Packet capture and network troubleshooting applies packet-level evidence to incident diagnosis.
- Network observability covers metrics, logs, traces, and flow records for following a request.
- RFC 1122: Requirements for Internet Hosts: Communication Layers documents requirements for the Internet host communication layers.
- RFC 9293: Transmission Control Protocol (TCP) specifies modern TCP behavior.
- RFC 8200: Internet Protocol, Version 6 (IPv6) Specification specifies IPv6.
Conclusion
OSI gives networking a seven-layer vocabulary; TCP/IP groups the protocols and functions used by the Internet into a practical stack. Their layers overlap without matching perfectly. For troubleshooting, trace the request from name resolution and routing through transport, TLS, and the application, then use observed evidence to narrow the fault. The diagrams help organize the work, but the protocol and component logs explain what actually happened.
Category
Related Posts
Network Encapsulation: Follow a Packet Across the Stack
Follow an HTTPS request from a browser through transport, IP, and link layers, and learn how headers, MTU, routers, and packet captures fit together.
Packet Capture and Network Troubleshooting: Layered Workflow
Use a layered workflow to diagnose DNS, route, TCP, TLS, and HTTP failures with ping, curl, tcpdump, and Wireshark, then collect useful incident evidence.
Trace and Secure a Web Request
Trace a web request from DNS through routing, TCP, TLS, and HTTP with safe commands, then classify failures and review least-privilege security evidence.