Protocol layers and encapsulation
Layered architecture
To manage the complexity of network design, network protocols are organized into layers.
Each layer performs specific functions and provides services to the layer above it while relying on services from the layer below.
Benefits of layering:
- offers conceptual clarity and modularity
- makes the system easier to understand: allows discussing a well-defined, specific part of a large and complex system
- makes the system easier to update: you can change how a layer works without disrupting the rest of the system, as long as it still performs the same service
Drawbacks of layering:
- possible duplication of functionality (e.g., error recovery at multiple layers)
- some features may require cross-layer information, which challenges the strict separation between layers
Protocol layers can be implemented in software, hardware, or both:
- application and transport layers are implemented in software on end systems
- physical and data link layers are implemented in hardware (e.g., network interface cards)
- the network layer often uses a combination of software and hardware
The TCP/IP stack
The set of protocols across all layers is called a protocol stack.
The Internet protocol stack is commonly called the TCP/IP stack because it is built around the core protocols TCP and IP.
The TCP/IP stack includes five layers:
| Layer | Responsibilities | Examples | Data Unit |
|---|---|---|---|
|
Application Layer |
|
HTTP, SMTP, DNS |
Messages |
|
Transport Layer |
|
TCP, UDP |
Segments |
|
Network Layer |
|
IP, routing protocols |
Datagrams |
|
Link Layer |
|
Ethernet, WiFi, PPP |
Frames |
|
Physical Layer |
|
twisted-pair copper wire, coaxial cable, fiber optics |
Packets/Bits |
This stack enables the reliable transmission of data from one application on one device to another across diverse physical and logical paths.
Encapsulation
Encapsulation is the process of wrapping data with protocol-specific headers as it passes through the layers of a network protocol stack.
At the sending host, an application-layer message is passed down the stack:
- the transport layer adds a header (creating a segment)
- the network layer adds its header (creating a datagram)
- the link layer adds its header (creating a frame)
Each lower layer treats the data from the layer above as its payload:
Hosts implement all 5 layers but routers and link-layer switches have protocol stacks only for the lower layers:
- switches: layers 1–2
- routers: layers 1–3
Encapsulation can be more complex when messages are split into multiple segments or datagrams that must later be reassembled.