Layers and encapsulation
Networking is divided into layers, each providing a service to the one above. Layering tames complexity, and encapsulation is how layers cooperate on every packet.
Why layers
A network must handle physical signals, local delivery, global routing, reliable delivery, and applications. Layering splits these tasks so each layer offers a service to the layer above using the layer below, and can change independently: Wi-Fi can replace Ethernet without changing web browsers, and new applications need no changes to routers.
The internet protocol stack
The internet is usually described in five layers. Application: protocols for specific uses, such as HTTP, SMTP, and DNS. Transport: delivery between processes, TCP and UDP. Network: routing datagrams between hosts across networks, IP. Link: moving frames between neighbouring nodes, Ethernet and Wi-Fi. Physical: moving bits as signals on a medium.
The OSI model
The International Organization for Standardization's Open Systems Interconnection (OSI) reference model, published in 1984, has seven layers: physical, data link, network, transport, session, presentation, and application. The internet merges session and presentation functions, such as encryption and data formats, into applications. OSI's numbering remains common vocabulary: 'layer 2 switch', 'layer 3 routing', 'layer 7 load balancer'.
Encapsulation
As data moves down the stack, each layer adds its own header: the application's message becomes the payload of a transport segment, which becomes the payload of a network-layer datagram, which becomes the payload of a link-layer frame. On arrival, each layer strips its header and passes the payload up. Names differ by layer: message, segment, datagram (or packet), frame.
Which devices use which layers
Hosts implement all five layers. Routers implement the physical, link, and network layers: they read IP headers to forward datagrams. Link-layer switches implement physical and link layers, forwarding frames by MAC address. Middleboxes such as firewalls, network address translators, and load balancers may also inspect transport or even application headers, breaking strict layering.
Protocols and interfaces
A protocol defines the format and order of messages exchanged between peers at the same layer and the actions taken on sending or receiving them. A service interface defines what a layer offers to the layer above, such as 'reliable byte stream' for TCP. Peers at each layer communicate logically, while data actually travels down one stack, across the link, and up the other.
Costs of layering
Layering has costs: each header adds overhead, functions may be duplicated across layers, and strict separation can hide information that would help, such as whether loss is caused by congestion or radio interference. Real systems sometimes deliberately cross layers for performance, but the layered model remains the main way to understand and design networks.
Worked example
A 1,000-byte HTTP request is sent over TCP, IPv4, and Ethernet. TCP adds a 20-byte header (without options), giving 1,020 bytes; IPv4 adds 20 bytes, giving 1,040; Ethernet adds a 14-byte header and 4-byte frame check, giving 1,058 bytes on the wire, excluding the preamble. The overhead is about 5.5%. A router along the way removes the Ethernet frame, reads the IP header, and re-encapsulates the datagram in a new frame for the next link.
Key takeaways
Layering divides networking into services that can evolve independently. The five-layer internet stack is application, transport, network, link, and physical. The seven-layer OSI model (1984) adds session and presentation and supplies layer numbers. Encapsulation wraps a message in segment, datagram, and frame headers, removed in reverse at the receiver. Hosts use all layers; routers use up to the network layer; switches up to the link layer; middleboxes may look deeper. Protocols define peer messages; interfaces define services. Layering adds overhead and hides information but remains the essential design tool.
Flashcard
Dividing networking into stacked services
Check your understanding
A router receives an Ethernet frame carrying an IP datagram. Which headers does it normally examine to forward the packet?
