Internet Backend 01 ๐ The OSI 7-Layer Model
The OSI model is a conceptual framework, not an implementation. It divides the task of moving data between two hosts into seven layers, each with a specific responsibility, each depending on the layer below it to provide a service and the layer above it to consume one. The model was designed by the International Organization for Standardization as a reference for how network protocols should be structured, and it remains the vocabulary that network engineers use to describe where a problem lives. A packet loss is a layer 3 problem. A corrupted frame is a layer 2 problem. A TLS handshake failure is a layer 6 problem. The layers are not a physical stack in the wire. They are the abstraction that makes the stack legible, and the abstraction is the reason a switch, a router, and a browser can each do their job without knowing what the other two are doing.
The model was published in 1984 as the OSI Reference Model, and it was intended to be the standard that all networks would follow. The TCP/IP suite won the protocol war, but the OSI model won the vocabulary war. The seven layers are still the way network engineers describe the stack, the way the certification exams test the stack, and the way the troubleshooting procedures are organized. The model is not the implementation. It is the map, and the map is useful even when the territory has been rearranged.
Key point: The OSI model has seven layers: Physical, Data Link, Network, Transport, Session, Presentation, and Application. Each layer provides a service to the layer above it and consumes a service from the layer below it. The encapsulation is the mechanism that adds a header at each layer, and the decapsulation is the mechanism that removes it. The model is conceptual; the TCP/IP suite is the implementation that most networks use.
Why the layered model exists
The interoperability problem. A network has many vendors: the cable manufacturer, the switch vendor, the router vendor, the operating system, and the application developer. Each vendor implements a subset of the stack, and the layers are the contract that allows the subsets to interoperate. A switch implements the Physical and Data Link layers, and it does not need to know whether the payload is an IP packet or an ARP request. A router implements the Physical, Data Link, and Network layers, and it does not need to know whether the transport is TCP or UDP. A browser implements the Application layer, and it does not need to know whether the link is Ethernet or Wi-Fi. The layering is the boundary that makes the interoperability possible, because each vendor only needs to implement the contract at its layer, not the entire stack.
The abstraction problem. The layers hide the complexity of the lower layers from the upper layers. An application does not need to know whether the data is sent over Ethernet, Wi-Fi, or a cellular link. It only needs to know that the transport layer will deliver the bytes in order (if it is TCP) or not (if it is UDP). The abstraction is the mechanism that allows the application to be written once and run on any network. The abstraction is also the mechanism that allows the network to evolve without the application changing. The transition from IPv4 to IPv6 is a layer 3 change, and the application that uses the transport layer does not need to know which version is in use.
The troubleshooting problem. When something breaks, the layers are the diagnostic checklist. The cable is unpluggedโlayer 1. The switch port is downโlayer 2. The IP address is wrongโlayer 3. The port is blockedโlayer 4. The TLS certificate is expiredโlayer 6. The HTTP request is malformedโlayer 7. The layers tell the engineer where to look, and the encapsulation tells them what to inspect. A packet capture that shows the frame header but not the IP header is a capture at layer 2. A capture that shows the IP header but not the TCP header is a capture at layer 3. The layer is the scope of the evidence.
The trade-off. The OSI model is conceptual, and the real networks do not follow it exactly. The TCP/IP suite is the implementation that the Internet uses, and it has four or five layers, not seven. The Session and Presentation layers are often folded into the Application layer, or into the Transport layer, because their functions are handled by the application or the lower layers in practice. The OSI model is the reference, and the TCP/IP model is the reality, and the two are not identical. The model is still useful because the vocabulary is shared, and the troubleshooting procedure is still organized by the layers.
a. The lower layers: Physical, Data Link, and Network
The Physical layer is the hardware. It defines the electrical, mechanical, and procedural characteristics of the transmission medium. The voltage levels, the cable pinouts, the radio frequencies, and the bit rate are the Physical layer concerns. It moves the bits, and it does not know what the bits mean. The Physical layer’s PDU is the bit. The devices at this layer are the hub, the repeater, the cable, and the radio antenna. The hub is a layer 1 device because it repeats the signal from one port to every other port, with no addressing and no filtering. The repeater is a layer 1 device because it regenerates the signal to extend the distance. The Physical layer does not detect errors, does not address the devices, and does not route the data. It only moves the bits.
The Data Link layer is the framing and the local delivery. It takes the bits from the Physical layer and assembles them into frames. The frame contains the hardware addressโthe MAC address on Ethernetโof the sender and the receiver, and a checksum that detects the transmission errors. The Data Link layer is divided into two sublayers. The Logical Link Control (LLC) sublayer handles the multiplexing of the protocols over the same physical link. The Media Access Control (MAC) sublayer handles the physical addressing and the media access control, which is the mechanism that decides which device can transmit on a shared medium. The Data Link layer’s PDU is the frame. The devices at this layer are the switch and the bridge. The switch is a layer 2 device because it forwards the frames based on the MAC address, and it maintains a MAC address table that maps the MAC address to the switch port. The bridge is the older equivalent of the switch, and it does the same thing with fewer ports.
The Data Link layer’s functions include the framing, the physical addressing, the flow control, the error control, and the access control. The framing is the mechanism that delimits the start and the end of the frame. The physical addressing is the MAC address in the frame header. The flow control is the mechanism that prevents the sender from overwhelming the receiver, and it is implemented in some Data Link protocols but not in Ethernet. The error control is the checksum in the frame trailer, which is the Frame Check Sequence (FCS), and it detects the transmission errors but does not correct them. The access control is the mechanism that decides which device can transmit on a shared medium, and it is the Carrier Sense Multiple Access with Collision Detection (CSMA/CD) on the classic Ethernet, and the Carrier Sense Multiple Access with Collision Avoidance (CSMA/CA) on Wi-Fi.
The Data Link frame:
[Destination MAC (6 bytes)][Source MAC (6 bytes)][EtherType (2 bytes)][Payload (46-1500 bytes)][FCS (4 bytes)]
The frame header is 14 bytes: the destination MAC, the source MAC, and the EtherType. The EtherType is the field that tells the receiver which Network layer protocol is in the payload. The 0x0800 is IPv4, the 0x86DD is IPv6, and the 0x0806 is ARP. The frame trailer is 4 bytes: the FCS, which is the CRC-32 checksum. The payload is 46 to 1500 bytes: the minimum is 46 because the classic Ethernet requires the frame to be at least 64 bytes, and the maximum is 1500 because the Maximum Transmission Unit (MTU) is 1500 bytes. The frame is the unit that the switch forwards, and the MAC address is the unit that the switch uses to decide which port to forward to.
The Network layer is the logical addressing and the routing. It takes the segments from the Transport layer and encapsulates them into packets. The packet contains the source and destination IP addresses, and the Network layer is responsible for routing the packet from the source host to the destination host across multiple networks. The Network layer’s PDU is the packet. The devices at this layer are the router and the layer 3 switch. The router is a layer 3 device because it forwards the packets based on the IP address, and it maintains a routing table that maps the destination network to the next hop. The layer 3 switch is a switch that also does the routing, and it is the device that blurs the line between the layers.
The Network layer’s functions include the logical addressing, the routing, the fragmentation, and the error reporting. The logical addressing is the IP address in the packet header. The routing is the mechanism that decides the path from the source to the destination, and it is the function that the router performs. The fragmentation is the mechanism that splits a packet that is larger than the MTU into smaller packets, and it is the function that the source host or the router performs. The error reporting is the ICMP protocol, which is the mechanism that reports the unreachable destinations and the time exceeded conditions. The Network layer does not guarantee the delivery; it only makes the best effort to route the packet. The reliability, if it is needed, is the Transport layer’s responsibility.
The IP packet:
[Version (4 bits)][IHL (4 bits)][DSCP (6 bits)][ECN (2 bits)][Total Length (16 bits)]
[Identification (16 bits)][Flags (3 bits)][Fragment Offset (13 bits)]
[TTL (8 bits)][Protocol (8 bits)][Header Checksum (16 bits)]
[Source IP (32 bits)][Destination IP (32 bits)]
[Options (variable)][Padding (variable)]
[Payload (the TCP segment or the UDP datagram)]
The IP header is 20 bytes minimum. The version is 4 for IPv4 and 6 for IPv6. The IHL is the header length in 32-bit words. The total length is the length of the packet in bytes, including the header and the payload. The identification, the flags, and the fragment offset are the fields that the fragmentation uses. The TTL is the time-to-live, which is decremented by every router, and the packet is dropped when it reaches zero. The TTL is the mechanism that prevents the routing loops. The protocol field is the field that tells the receiver which Transport layer protocol is in the payload: 6 is TCP, 17 is UDP, and 1 is ICMP. The source and destination IP addresses are the logical addresses.
b. The upper layers: Transport, Session, Presentation, and Application
The Transport layer is the end-to-end communication between the processes. It takes the data from the application and breaks it into segments, and it adds the source and destination port numbers. The port numbers are the mechanism that identifies the application on the host; the IP address identifies the host, and the port number identifies the process. The Transport layer’s PDU is the segment (TCP) or the datagram (UDP). The devices at this layer are the load balancer and the firewall, although the firewall can operate at multiple layers. The load balancer is a layer 4 device when it forwards the connections based on the port, and it is a layer 7 device when it forwards the requests based on the HTTP header.
The Transport layer is where the TCP and UDP live. TCP provides the reliable, ordered delivery with the acknowledgments, the retransmissions, and the three-way handshake. TCP’s header includes the source and destination ports, the sequence and acknowledgment numbers, the flags, the window size, and the checksum. The sequence number is the mechanism that orders the segments, the acknowledgment number is the mechanism that confirms the receipt, the flags are the mechanism that controls the connection (SYN, ACK, FIN, RST), the window size is the mechanism that controls the flow, and the checksum is the mechanism that detects the errors. UDP provides the connectionless, unreliable delivery with no handshake and no retransmission. UDP’s header includes the source and destination ports, the length, and the checksum. UDP is the choice for the applications that prefer the low latency over the reliability, such as the DNS, the DHCP, the streaming, and the gaming.
The TCP segment:
[Source Port (16 bits)][Destination Port (16 bits)]
[Sequence Number (32 bits)][Acknowledgment Number (32 bits)]
[Data Offset (4 bits)][Reserved (3 bits)][Flags (9 bits)][Window Size (16 bits)]
[Checksum (16 bits)][Urgent Pointer (16 bits)]
[Options (variable)][Padding (variable)]
[Payload]
The TCP header is 20 bytes minimum. The source and destination ports are the application identifiers. The sequence number is the position of the first byte of the payload in the byte stream. The acknowledgment number is the next byte that the sender expects to receive. The flags are the control bits: the SYN, the ACK, the FIN, the RST, the PSH, and the URG. The window size is the number of bytes that the receiver is willing to accept, and it is the flow control mechanism. The checksum is the error detection mechanism, and it covers the header and the payload and a pseudo-header that includes the IP addresses.
The Session layer is the connection management. It opens, maintains, and terminates the communication sessions between the applications. The session is the logical connection that persists across multiple requests, and the Session layer is the mechanism that keeps it alive. In practice, the Session layer is often folded into the Application layer, because the application protocols (HTTP, WebSocket) handle the session management themselves. The HTTP cookie is the session mechanism, and the WebSocket connection is the session mechanism, and both are implemented at the Application layer. The Session layer’s functions include the session establishment, the session maintenance, the session termination, and the session synchronization. The RPC (Remote Procedure Call) is the classic example of a Session layer protocol, and the session is the context that the RPC maintains across the calls.
The Presentation layer is the data representation. It handles the encoding, the compression, and the encryption. The character encoding (ASCII, UTF-8), the image formats (JPEG, PNG), and the encryption (TLS) are the Presentation layer concerns. The layer ensures that the data sent by one host is understood by the other, regardless of the internal representation. The big-endian versus the little-endian is the classic Presentation layer problem, and the network byte order (big-endian) is the convention that the protocols use. The MIME types are the Presentation layer mechanism, and the Content-Type header is the Application layer’s use of it. In practice, the Presentation layer is also often folded into the Application layer, because the application protocols handle the encoding and the TLS is handled by the library. The TLS is the most important Presentation layer protocol in the modern stack, and it provides the encryption, the integrity, and the authentication.
The Application layer is the interface to the user. It is the layer that the applications interact with, and it contains the protocols that the applications use: HTTP, DNS, SMTP, FTP, and the others. The Application layer is not the application itself; it is the protocol that the application uses to communicate over the network. A browser is an application, and HTTP is the Application layer protocol that the browser uses. The Application layer’s functions include the network services, the resource sharing, the remote file access, and the directory services. The HTTP is the most important Application layer protocol for the frontend developers, and the DNS is the most important for the backend developers.
Complete Example Session
// ============================================
// PART 1: THE PHYSICAL LAYER
// ============================================
// The bits on the wire.
// The voltage levels, the cable pinouts, the radio frequencies.
// The Physical layer moves the bits and does not know what they mean.
// The devices: the hub, the repeater, the cable.
// The PDU: the bit.
// ============================================
// PART 2: THE DATA LINK LAYER
// ============================================
// The frame.
// The frame header contains the destination MAC, the source MAC, and the EtherType.
// The frame trailer contains the FCS (CRC-32).
// The switch forwards the frame based on the MAC address.
// The devices: the switch, the bridge.
// The PDU: the frame.
// The frame:
// [Destination MAC (6)][Source MAC (6)][EtherType (2)][Payload (46-1500)][FCS (4)]
// ============================================
// PART 3: THE NETWORK LAYER
// ============================================
// The packet.
// The IP header contains the source and destination IP addresses.
// The router forwards the packet based on the IP address.
// The Network layer does not guarantee the delivery.
// The devices: the router, the layer 3 switch.
// The PDU: the packet.
// The IP header:
// [Version][IHL][DSCP][ECN][Total Length][Identification][Flags][Fragment Offset]
// [TTL][Protocol][Header Checksum][Source IP][Destination IP]
// ============================================
// PART 4: THE TRANSPORT LAYER
// ============================================
// The segment (TCP) or the datagram (UDP).
// The TCP header contains the source and destination ports.
// The port number identifies the application on the host.
// TCP provides the reliable, ordered delivery.
// UDP provides the connectionless, unreliable delivery.
// The devices: the load balancer (layer 4), the firewall.
// The PDU: the segment (TCP) or the datagram (UDP).
// The TCP header:
// [Source Port][Destination Port][Sequence Number][Acknowledgment Number]
// [Data Offset][Reserved][Flags][Window Size][Checksum][Urgent Pointer]
// ============================================
// PART 5: THE SESSION LAYER
// ============================================
// The session management.
// The opening, maintaining, and terminating of the connections.
// In practice, often folded into the Application layer.
// The examples: the RPC, the HTTP cookie session, the WebSocket.
// The PDU: the data.
// ============================================
// PART 6: THE PRESENTATION LAYER
// ============================================
// The data representation.
// The encoding, the compression, the encryption.
// In practice, often folded into the Application layer.
// The TLS is the Presentation layer concern.
// The examples: the TLS, the JPEG, the UTF-8, the MIME.
// The PDU: the data.
// ============================================
// PART 7: THE APPLICATION LAYER
// ============================================
// The protocol that the application uses.
// HTTP, DNS, SMTP, FTP.
// The Application layer is not the application itself.
// The PDU: the data.
// ============================================
// PART 8: THE ENCAPSULATION
// ============================================
// The data is encapsulated at each layer.
// The Application layer: the data.
// The Transport layer: [TCP header][data].
// The Network layer: [IP header][TCP header][data].
// The Data Link layer: [Frame header][IP packet][Frame trailer].
// The Physical layer: the bits.
// The receiving host decapsulates:
// The Physical layer: the bits to the frame.
// The Data Link layer: the frame to the packet.
// The Network layer: the packet to the segment.
// The Transport layer: the segment to the data.
// The Application layer: the data to the application.
// ============================================
// PART 9: THE TROUBLESHOOTING PROCEDURE
// ============================================
// Step 1: the Physical layer.
// The cable is plugged in. The link light is on. The interface is up.
// The command: ip link show.
// Step 2: the Data Link layer.
// The MAC address is correct. The switch port is up. The VLAN is correct.
// The command: arp -a, ip neigh.
// Step 3: the Network layer.
// The IP address is correct. The subnet mask is correct. The route exists.
// The command: ip addr, ip route, ping.
// Step 4: the Transport layer.
// The port is open. The firewall allows the port. The service is listening.
// The command: ss -tlnp, nc -zv host port.
// Step 5: the Session layer.
// The session is established. The authentication is valid.
// The command: the application logs.
// Step 6: the Presentation layer.
// The TLS certificate is valid. The encoding is correct.
// The command: openssl s_client -connect host:443.
// Step 7: the Application layer.
// The request is correct. The response is correct.
// The command: curl -v.
// ============================================
// PART 10: THE CHECKLIST
// ============================================
// [ ] The Physical layer is the hardware.
// [ ] The Data Link layer is the framing and the MAC addressing.
// [ ] The Network layer is the IP addressing and the routing.
// [ ] The Transport layer is the TCP/UDP and the port numbers.
// [ ] The Session layer is the connection management.
// [ ] The Presentation layer is the encoding and the encryption.
// [ ] The Application layer is the protocol (HTTP, DNS, etc.).
// [ ] The encapsulation is understood.
// [ ] The troubleshooting procedure is followed from layer 1 to layer 7.
The ten parts covered the seven layers, the encapsulation, the troubleshooting procedure, and the checklist. The through-line is that the layers are the abstraction, and the encapsulation is the mechanism.
Quick Reference
The seven layers
| Layer | Number | PDU | Addressing | Devices | Protocols |
|---|---|---|---|---|---|
| Application | 7 | Data | โ | โ | HTTP, DNS, SMTP |
| Presentation | 6 | Data | โ | โ | TLS, JPEG, UTF-8 |
| Session | 5 | Data | Session ID | โ | RPC, WebSocket |
| Transport | 4 | Segment / Datagram | Port | Load balancer | TCP, UDP |
| Network | 3 | Packet | IP address | Router | IP, ICMP |
| Data Link | 2 | Frame | MAC address | Switch | Ethernet, Wi-Fi |
| Physical | 1 | Bit | โ | Hub, repeater | โ |
The encapsulation
| Layer | PDU | Header | Trailer |
|---|---|---|---|
| Application | Data | โ | โ |
| Transport | Segment / Datagram | TCP/UDP header | โ |
| Network | Packet | IP header | โ |
| Data Link | Frame | Frame header | FCS |
| Physical | Bits | โ | โ |
The troubleshooting commands
| Layer | Command | Check |
|---|---|---|
| 1 | ip link show | The interface is up |
| 2 | ip neigh | The MAC address is resolved |
| 3 | ip addr, ip route, ping | The IP and the route |
| 4 | ss -tlnp, nc -zv | The port is open |
| 5 | The application logs | The session is valid |
| 6 | openssl s_client | The TLS certificate |
| 7 | curl -v | The request and the response |
The TCP/IP mapping
| OSI | TCP/IP | Notes |
|---|---|---|
| Application, Presentation, Session | Application | The three are folded into one |
| Transport | Transport | TCP, UDP |
| Network | Internet | IP, ICMP |
| Data Link, Physical | Network Access | The link and the physical |
Best Practices
โ Do This:
// Use the layers to troubleshoot
// Start at layer 1 and move up.
// The cable is unplugged โ layer 1
// The switch port is down โ layer 2
// The IP address is wrong โ layer 3
// The port is blocked โ layer 4
// The TLS certificate is expired โ layer 6
// The HTTP request is malformed โ layer 7
โ Don’t Do This:
// Assume the OSI model is the implementation
// The TCP/IP suite is the implementation; the OSI is the reference.
// Start troubleshooting at layer 7
// The physical link is the first thing to verify.
Common Pitfalls
| Pitfall | Why It Happens | Fix |
|---|---|---|
| The layer confusion | The model is conceptual, and the implementations combine the layers | Use the TCP/IP model for the implementation |
| The Session and Presentation layers are ignored | They are folded into the Application layer in practice | Remember that TLS is the Presentation layer |
| The encapsulation is misunderstood | The headers are added at each layer | Use the packet capture to see the headers |
| The troubleshooting starts at layer 7 | The application error is the visible symptom | Start at layer 1 and move up |
| The switch is confused with the router | Both forward the data | The switch uses the MAC address; the router uses the IP address |
Summary
| Item | Value |
|---|---|
| The model | Seven layers, conceptual |
| The lower layers | Physical, Data Link, Network |
| The upper layers | Transport, Session, Presentation, Application |
| The encapsulation | The header added at each layer |
| The implementation | The TCP/IP suite |
| The troubleshooting | The layers are the checklist |
| The PDU | Bit, Frame, Packet, Segment, Data |
Key takeaways:
- The OSI model is a conceptual framework with seven layers. Each layer provides a service to the layer above it and consumes a service from the layer below it. The Physical layer moves the bits, the Data Link layer frames them, the Network layer routes them, the Transport layer delivers them, and the Application layer uses them.
- The encapsulation is the mechanism that adds a header at each layer. The Transport layer adds the TCP or UDP header, the Network layer adds the IP header, and the Data Link layer adds the frame header and the trailer. The receiving host reverses the process.
- The TCP/IP suite is the implementation, and it does not match the OSI model exactly. The TCP/IP model has four or five layers, and the Session and Presentation layers are folded into the Application layer because their functions are handled by the application or the lower layers in practice.
- The layers are the troubleshooting checklist. A layer 1 problem is a cable. A layer 3 problem is an IP address. A layer 4 problem is a port. A layer 7 problem is an HTTP request. The layer tells the engineer where to look, and the troubleshooting procedure starts at layer 1 and moves up.
- The devices operate at specific layers. The hub is layer 1, the switch is layer 2, the router is layer 3, the load balancer is layer 4 or 7, and the firewall is layer 3 to 7. The device’s layer determines what it can inspect and what it can forward.
Remember: The OSI model is the vocabulary, not the implementation. The seven layers are the abstraction that makes the network legible, and the encapsulation is the mechanism that makes the abstraction work. The TCP/IP suite is what the Internet actually uses, and it folds the Session and Presentation layers into the Application layer. The layers are the diagnostic checklist, and the encapsulation is the packet that the engineer inspects. The device’s layer is the scope of its inspection.
Stop using slow, ad-bloated tool sites! ๐คฎ
๐ Search “KandZ Tools” on Google to use many professional utilities for free.
KandZ.me is the ultimate minimalist hub for:
โ
Finance (Mortgage, Interest, Inflation)
โ
Tech (Base64, JSON, Dev Suite, IP)
โ
Health (BMI, BMR, TDEE)
โ
Productivity (Timer, Workspace, QR)
โก๏ธ Fast & Private
๐ No data leaves your device
๐ 100% Free
๐ Use it now: https://tools.kandz.me
๐ Bookmark itโyouโll need it later!