# OSI Data Flow
## How Data Flows Through the OSI Model
Understanding how data flows through the OSI model is fundamental to understanding how network communication works. Data flow through the OSI model involves two processes: encapsulation as data moves down the layers on the sending side, and decapsulation as data moves up the layers on the receiving side.
## Encapsulation Process on the Sending Side
When an application on Computer A wants to send data to an application on Computer B, the data begins at the Application layer of Computer A and travels downward through each layer. At each layer, additional header information specific to that layer is added to the data. This process of adding headers as data moves down the layers is called encapsulation.
At the Application layer, the application creates its message, for example an HTTP request containing the content of a web page request.
At the Presentation layer, the data may be encrypted and compressed.
At the Session layer, session information is added to manage the ongoing communication.
At the Transport layer, the data is divided into segments and TCP or UDP headers are added. The TCP header includes the source port number, destination port number, sequence number, and acknowledgment number.
At the Network layer, the segment is placed inside a packet and an IP header is added containing the source IP address and destination IP address.
At the Data Link layer, the packet is placed inside a frame and a frame header is added containing the source and destination MAC addresses. A trailer containing error detection information is also added.
At the Physical layer, the frame is converted into a stream of bits and transmitted as electrical signals, light pulses, or radio waves over the physical medium.
## Decapsulation Process on the Receiving Side
When the data arrives at Computer B, it enters at the Physical layer as a stream of bits and travels upward through each layer. At each layer, the header information added by the corresponding layer on the sending side is read, used to process the data correctly, and then stripped off before passing the data to the next layer. This process is called decapsulation.
At the Physical layer, the bits are received and assembled into a frame.
At the Data Link layer, the frame header is examined to confirm the destination MAC address matches the receiving device. The error detection information in the trailer is used to verify the frame was not damaged. The frame header and trailer are removed and the packet is passed to the Network layer.
At the Network layer, the IP header is examined to confirm the destination IP address. The packet is passed to the correct Transport layer protocol based on information in the IP header.
At the Transport layer, the TCP or UDP header is examined. If TCP is used, the sequence number is used to reassemble segments in the correct order and an acknowledgment is sent back to the sender. The Transport layer header is removed and the data is passed to the Session layer.
At the Session and Presentation layers, session management and data decryption or decompression are handled.
At the Application layer, the data arrives as the original message and the receiving application processes it.
## Peer Layer Communication
An important concept in the OSI model is that each layer on the sending device logically communicates with the same layer on the receiving device, even though physically the data flows down through all layers on the sending side, across the physical medium, and then up through all layers on the receiving side. This is called peer-to-peer communication. For example, the Transport layer on the sender and the Transport layer on the receiver communicate as if they have a direct connection, exchanging sequence numbers, acknowledgments, and flow control information, even though this information is physically carried within the lower layer structures.Back to Subject