Aprelius logo
uptime: 00:00:00
Network

Network Models and Encapsulation

OSI model

The OSI (Open Systems Interconnection) model is a conceptual framework for describing the different functions involved when network devices communicate. It is not a specification that real systems must follow, but a common way to organise and coordinate networking standards. There are 7 layers:

NameMain responsibilityExamples
ApplicationNetwork services used by applicationsHTTP, DNS, SMTP, SSH
PresentationData representation, encoding, compression, and encryptionTLS-related data transformations, character encoding
SessionEstablishing, managing, and synchronising communication sessionsSession management concepts
TransportEnd-to-end transport between hosts and transport endpointsTCP, UDP
NetworkCommunication between networks using packets and logical addressesIPv4, IPv6, ICMP
Data linkDelivery across a local-link using frames and link-layer addressesEthernet, Wi-Fi
PhysicalBits travel over a mediumCopper, fibre, radio

TCP/IP model

The TCP/IP model, also called the Internet protocol architecture, describes the layered protocol suite used by the Internet. A commonly used four-layer representation is:

TCP/IP layerOSI mappingMain responsibilityExamples
ApplicationApplication, Presentation, SessionApplication-level network protocolsHTTP, DNS, SSH, SMTP
TransportTransportEnd-to-end transportTCP, UDP
InternetNetworkInternetworking and IP addressingIPv4, IPv6, ICMP
LinkData link, PhysicalLocal-link delivery and transmissionEthernet, Wi-Fi

OSI vs TCP/IP

The two models serve different purposes:

  • OSI is primarily a general reference model for describing networking functions.
  • TCP/IP describes the architecture around the actual Internet protocol suite.
  • OSI separates Application, Presentation, and Session functionality; TCP/IP generally combines them into Application.
  • OSI separates Data Link and Physical; the common four-layer TCP/IP model combines them into Link.

Both at the end are just abstractions that help reason about protocols and responsibilities.

Layers

The upper layers

The OSI Application, Presentation, and Session layers are often merged together in Internet networking. The TCP/IP architecture uses a single Application layer rather than maintaining three separate layers, because it is sometimes difficult to clearly separate their functions. For example, HTTP/2 is specified as an application-layer protocol, but it includes binary framing, which can be viewed as presentation-like functionality, and stream multiplexing, which can be viewed as session-like functionality.

The models are useful for locating responsibility. They are not a claim that real systems contain seven or four perfectly separate pieces of hardware.

Transport layer

The Transport layer provides communication between transport endpoints on different hosts. TCP and UDP use port numbers to distinguish transport endpoints on a host.

  • TCP provides reliable delivery of a stream of bytes between apps running on different hosts. Sends bytes ordered, error-checked and if necessary retransmission them.
  • UDP provides a lightweight, connectionless protocol. It enables fast data transmission by sending datagrams directly to a target device without prior handshaking, flow control, or guaranteed delivery.

The transport layer is concerned with end-to-end communication. Routers normally do not need to understand TCP or UDP in order to forward an ordinary IP packet.

Network layer

The Network layer provides logical addressing and delivery across interconnected networks. IP addresses identify hosts/interfaces at this layer, while routers use routing information to choose where packets should go next.

The important distinction is:

IP answers where the packet should go; the link layer answers how to deliver it across the current link.

The Data Link layer handles communication over a directly connected network or link. Ethernet and Wi-Fi use frames and link-layer addresses such as MAC addresses.

The Physical layer defines how those frames are represented as signals on a medium such as copper, fibre, or radio. A physical network technology can involve both Data Link and Physical layer functionality. For example, Ethernet includes specifications spanning these two layers.

Encapsulation

When data is sent, each lower layer adds information needed to perform its function. This process is called encapsulation.

For a typical HTTP request transported using TCP over Ethernet, the conceptual process is:

text
Application data
      ↓
TCP segment
      ↓
IP packet
      ↓
Ethernet frame
      ↓
Physical signals

So in more details:

  1. The application creates application data, such as an HTTP request.
  2. TCP adds a TCP header containing information such as source and destination ports, sequence numbers, and control flags. The result is a TCP segment.
  3. IP adds an IP header containing information such as source and destination IP addresses. The result is an IP packet (or IP datagram).
  4. Ethernet adds a link-layer header and trailer around the IP packet. The result is an Ethernet frame.
  5. The Physical layer transmits the frame as signals representing bits over the medium.

The exact terminology depends on the protocol. For example, UDP normally calls its transport-layer unit a datagram, while TCP calls its unit a segment.

Headers and trailers

A layer can add both a header and, in some protocols, a trailer:

The Ethernet Frame Check Sequence (FCS) is part of the Ethernet frame trailer and is used for error detection on the link.

The important idea is that each layer adds metadata around the data it receives from the layer above.

Decapsulation

Process reversed to encapsulation, so reading data from layer 1 to layer 4 (or 7).

text
Ethernet frame
      ↓
IP packet
      ↓
TCP segment
      ↓
Application data

The receiving system processes the frame at the link layer, passes the IP payload to the Internet layer, passes the transport payload to TCP or UDP, and eventually delivers the application data to the appropriate application or socket.

Encapsulation and decapsulation are therefore complementary:

  • Encapsulation: headers/trailers are added as data moves down the stack.
  • Decapsulation: headers/trailers are processed and removed as data moves up the stack.

References

Glossary

datagram

A datagram is a self-contained unit of data sent without establishing a dedicated connection first. UDP calls its transport-layer units datagrams. Each one contains enough addressing information to be delivered independently, but delivery, ordering, and duplicate prevention are not guaranteed by UDP.

A local link is a directly connected network segment over which devices can exchange link-layer frames. Ethernet and Wi-Fi are examples of link technologies. A router terminates one link and may forward a packet onto another link.