In networking, a protocol defines the rules for communication between two entities. Implementations of protocols are typically organised as a stack of layers, each providing a distinct set of services to the layer above it and using services from the layer below it.
Why a Stack?
Separation of concerns – each layer handles a specific aspect of communication.
Modularity – layers can be developed, tested and replaced independently.
Interoperability – standardised interfaces allow different vendors’ equipment to work together.
Typical Layer Models
The most widely referenced models are the OSI (Open Systems Interconnection) model and the TCP/IP model. Both present a vertical stack, but the number of layers and their responsibilities differ.
OSI Model – Seven Layers
Layer (Top‑down)
Name
Primary Function
7
Application
Provides network services to end‑user applications (e.g., HTTP, SMTP).
6
Presentation
Data representation, encryption, compression.
5
Session
Establishes, manages and terminates sessions.
4
Transport
End‑to‑end reliability, flow control (e.g., TCP, UDP).
3
Network
Logical addressing and routing (e.g., IP).
2
Data Link
Physical addressing, error detection/correction on a link (e.g., Ethernet, PPP).
1
Physical
Transmission of raw bits over a medium (e.g., cables, radio).
TCP/IP Model – Four Layers
Application – Combines OSI’s Application, Presentation and Session layers.
Transport – Provides end‑to‑end services (TCP, UDP).
Internet – Handles logical addressing and routing (IP, ICMP).
Link – Encompasses OSI’s Data Link and Physical layers (Ethernet, Wi‑Fi).
How Data Moves Through the Stack
When a program sends data, the following steps occur (illustrated for the TCP/IP model):
Application Layer: Data is generated and possibly encoded (e.g., HTTP request).
Transport Layer: Data is segmented, a header with source/destination ports is added, and reliability mechanisms (ACK, retransmission) are applied if using TCP.
Internet Layer: Each segment receives an IP header containing source/destination IP addresses.
Link Layer: The packet is framed with MAC addresses and a CRC for error detection.
Physical Layer: The frame is converted to electrical, optical or radio signals and transmitted over the medium.
At the receiving end, each layer strips off its own header/footer (the reverse process) and passes the remaining data upward.
Mathematical \cdot iew of Layer Interaction
If we denote the data generated by the application as \$D\$, and each layer’s encapsulation function as \$E_i\$, then the transmitted bit‑stream \$B\$ can be expressed as:
Transport: Port multiplexing, reliability (TCP), connectionless service (UDP), congestion control.
Application: Protocols specific to user services (HTTP, FTP, DNS).
Implementation Considerations
When implementing a protocol stack, developers must decide:
Whether to implement a monolithic stack (all layers in one codebase) or a modular stack (separate libraries).
How to expose the interface between layers – usually via well‑defined function calls or message queues.
Performance trade‑offs: adding headers increases overhead; deep stacks may introduce latency.
Security: which layers need encryption or authentication (e.g., TLS at the Application layer, IPsec at the Network layer).
Suggested Diagram
Suggested diagram: A vertical stack showing the OSI/TCP‑IP layers with arrows indicating encapsulation (downward) and decapsulation (upward). Each layer box lists its main protocols and responsibilities.
Summary
Viewing protocol implementation as a stack clarifies how complex communication tasks are broken into manageable, reusable pieces. Each layer adds or removes its own control information, allowing the system to evolve, interoperate, and be debugged more easily.