The need for encapsulation
Sending a message over a network requires functions to be divided between layers. Data is prepared for transmission and receives control information. The receiver can use that information for error detection, delivery to the right destination, and interpretation. Encapsulation describes adding this information in a layered network architecture such as the OSI or TCP/IP model.
An international letter provides a concrete analogy for this division. The paper is not handed directly to a pilot. A message written on paper goes into an envelope with addresses, then into a local mailbag used for sorting, and later into a shipping container for international transport. Each stage adds packaging and instructions needed for one part of the route. Encapsulation applies a comparable sequence to network data.
The sending process: data flowing down the stack
Encapsulation occurs on the sending device as data moves down from the highest layer (Application) to the lowest (Physical). Each layer adds control information to the data received from the layer above, using a header and, in some protocols, a trailer. The data unit at a given layer is called a .
- Application, Presentation, Session Layers (7-5): The user application, such as a web browser or email client, creates the initial Data. It is formatted, compressed, or encrypted as needed.
- Transport Layer (4): The data is broken into smaller chunks. In TCP, the header contains port numbers that identify the application and sequence numbers used for reassembly. This PDU is a Segment in TCP. In UDP, it is a Datagram and includes port numbers among other fields.
- Network Layer (3): The segment is encapsulated with a header containing logical addresses. This creates a Packet.
- The identifies the packet source and destination in the network address space.
- Data Link Layer (2): The data-link layer creates a Frame from the packet. In a typical Ethernet frame, the packet receives a header and a trailer.
- The header contains link-layer addresses, known as , for the next hop on the local network.
- The trailer includes a Frame Check Sequence (FCS) used to detect frame errors. The FCS value is often calculated with CRC.
- Physical Layer (1): The frame is encoded as a stream of Bits or symbols and transmitted over the physical medium, for example as electrical voltages, light pulses, or radio waves.
The receiving process: data flowing up the stack
The receiving device performs the reverse process, known as Decapsulation. As data moves up the stack, each layer reads information from its corresponding header or trailer, processes it, and removes that information before passing the remaining PDU to the layer above.
- Physical Layer (1): Receives electrical, optical, or radio signals and recovers the bits from them. The receiving data-link interface assembles those bits into a Frame.
- Data Link Layer (2): Reads the source and destination MAC addresses. It verifies the FCS for transmission errors. After successful verification, it removes the frame's header and trailer and passes the Packet to the Network Layer.
- Network Layer (3): Examines the IP header and checks the packet's destination address. It then removes the IP header and passes the Segment or Datagram to the Transport Layer.
- Transport Layer (4): Processes the header information. In TCP, it uses sequence numbers to reassemble the data in the correct order. Once reassembled, it removes the transport header and delivers the raw Data to the correct application based on the port number.
- Application, Presentation, Session Layers (7-5): The upper layers receive the data, reverse any compression or encryption that was applied, and present it to the end-user application in a usable format.