Table of Contents
Role of the Transport Layer
The transport layer is responsible for getting data from one application on a device to an application on another device, in the correct order, without unnecessary duplication or loss. It sits above the network layer, which only knows about host to host delivery, and below the session and application layers, which care about user interactions and data formats.
Where the network layer focuses on “which computer should this packet go to,” the transport layer focuses on “which program on that computer should receive this data, and in what condition.” It introduces the idea of ports, connections, reliability, and flow control. These ideas are implemented in well known protocols such as TCP and UDP, which are covered in their own sections.
The transport layer can provide connections that behave like a reliable stream of bytes, as well as simple connectionless communication where speed is more important than reliability. It does this by adding its own header on top of the network layer packet, creating the unit often called a segment for TCP or a datagram for UDP.
End to End Communication
The transport layer is the first layer that sees communication as an end to end relationship between two applications rather than just between two interfaces or two networks. It maintains information about each communication, such as which ports are used, what sequence the data is in, and how much data has been acknowledged.
In an end to end communication, the transport layer identifies each participant using a combination of IP address and port number. Together, the source IP, source port, destination IP, and destination port form what is often called a socket pair. This socket pair uniquely identifies a single transport layer conversation among many other simultaneous conversations.
When you open a web page, start a video call, and receive email at the same time, each of these is a separate transport layer conversation, each defined by its own socket pair. The transport layer keeps these independent so that data from one application is not mixed up with another.
Multiplexing and Demultiplexing
Multiplexing at the transport layer means taking data from many applications on one host and combining their transport segments so that they can all share the same network connection. Demultiplexing is the opposite, where incoming segments are examined so that data is delivered to the correct application.
To achieve this, the transport header includes at least a source port and a destination port. When an application wants to send data, it chooses or is given a source port. It specifies the destination port of the application it wants to reach on the remote host. The transport layer then adds these port numbers to the header before passing the segment to the network layer.
On the receiving side, the transport layer reads the destination port in each segment. It checks which local application is bound to that port and hands the data to that application. If several applications are sending and receiving at once, their data is separated correctly based on these port numbers.
Port numbers below 1024 are usually reserved for well known services, while higher port numbers are used dynamically for client connections. The details of port types and usage are expanded further when discussing ports and sockets, but at the transport layer the important idea is that multiplexing and demultiplexing rely on ports.
Connection Oriented vs Connectionless Service
The transport layer can provide two different styles of service to applications, connection oriented and connectionless. These are not abstract ideas only, they directly map to two main families of transport protocols described in separate sections.
Connection oriented service treats communication as a virtual conversation that has a beginning, a middle, and an end. Before data flows, a setup phase creates state information about the connection. During the conversation, the transport layer tracks sequence information, acknowledgments, and possibly window sizes. When the conversation is finished, a teardown phase clears this state. This style is useful when applications need reliability, ordered delivery, and clear boundaries for a session.
Connectionless service, in contrast, sends individual messages without setting up or maintaining a connection. Each message is handled independently. The transport layer does not maintain information about past messages and does not guarantee delivery, order, or protection against duplicates. This style is useful for applications that value low delay and can tolerate some loss, or that handle reliability in their own way.
From the point of view of the application, choosing between these services is a question of tradeoffs. Connection oriented service tends to use more overhead and processing in return for better reliability and control. Connectionless service is lighter and often faster, but shifts responsibility to the application if reliability is required.
Reliability and Ordered Delivery
One of the most important capabilities that the transport layer can offer is reliable and ordered delivery of data. Not all transport protocols provide this, but when they do, they hide many imperfections of the underlying network from the application.
In a real network, packets can be lost, delayed, duplicated, or arrive out of order. The transport layer can compensate for these problems using several mechanisms. It adds sequence numbers to data segments so that the receiver can detect missing or duplicate segments and can reorder data correctly. It also uses acknowledgments, where the receiver informs the sender which data has arrived successfully.
If a sender does not receive an acknowledgment for certain data within a given time, it can assume that the data or the acknowledgment was lost and can retransmit. This is coordinated through timers. The exact behavior of these mechanisms is part of the specific transport protocol, but the general concept belongs to the transport layer.
Ordered delivery ensures that the data presented to the application is in the same sequence as it was sent, even if lower layers delivered segments to the transport layer in a different order. Without ordered delivery, applications that depend on sequence would have to handle reordering on their own, which is often complex.
Reliable ordered delivery at the transport layer means:
- Every piece of data is either delivered correctly to the receiving application or the sender is informed of failure.
- Data is presented to the receiving application in the exact order it was sent, with duplicates removed.
These guarantees do not mean that failures never happen, but that the transport layer manages them in a way that keeps the application view simple.
Flow Control
Flow control at the transport layer protects the receiver from being overwhelmed by a sender that transmits data too quickly. It is an end to end mechanism and is different from any kind of congestion control that reacts to conditions in the network itself.
Imagine a powerful server sending data to a small device with limited memory and processing power. Without flow control, the server could send data faster than the device can process and store it. Buffers would fill up and data would have to be discarded. The transport layer can prevent this by letting the receiver influence the sender’s sending rate.
To achieve flow control, the receiving side typically advertises how much buffer space it has available for that particular conversation. The sending side limits its unacknowledged data so that it does not exceed this advertised capacity. If the receiver temporarily cannot accept more data, it can reduce the allowed amount. When it can receive again, it can increase the advertised value.
Flow control is a property of the connection between two endpoints at the transport layer. It is based on how fast the receiver can handle data and how much it can buffer, not on how congested the network is. This separation of concerns allows the transport layer to tune communication for each pair of applications independently of the rest of the network.
Transport layer flow control rule:
The sender must not have more unacknowledged data in transit than the amount the receiver has advertised it can accept.
This simple rule underlies more complex algorithms used by specific transport protocols to implement flow control.
Basic Transport Layer Header Fields
Although different transport protocols have different header formats, most transport layer headers share some basic fields. These fields allow the transport layer to perform multiplexing, reliability, and flow control.
The most common basic fields are summarized in the table below. The exact presence and use of each field depends on the protocol family, but the ideas are the same.
| Header Field | Purpose |
|---|---|
| Source Port | Identifies the sending application on the source host |
| Destination Port | Identifies the receiving application on the destination |
| Sequence Number | Labels data for ordering and loss detection |
| Acknowledgment Info | Confirms receipt of data from the other side |
| Control Flags | Mark control messages like start or end of a connection |
| Window / Flow Info | Communicates receiver capacity for flow control |
| Checksum | Detects errors in the header and data |
The presence of sequence numbers and acknowledgment information allows the transport layer to create the illusion of a simple, reliable channel even when the underlying network is unreliable. Control flags allow the layer to distinguish data segments from connection management messages. Window or similar fields carry flow control information. The checksum protects against accidental corruption of the segment.
From the application’s perspective, these details are usually hidden. The application sends and receives data through an interface provided by the operating system, while the transport layer uses these header fields to implement the required behavior.
Interaction With Other Layers
The transport layer sits at a pivotal position in the OSI model. It receives packets from the network layer that have already been delivered to the correct host. It then checks whether they belong to an existing conversation, whether they are in sequence, whether they need acknowledgment, and which application should receive them.
In the other direction, when an application sends data, the transport layer accepts the data stream or messages, breaks them into appropriately sized segments, adds the necessary header information, and hands the segments to the network layer for routing across the network.
Because it has an end to end view of each conversation, the transport layer can shield the application from many network details. Applications do not need to know how many routers are between the two hosts, how the network handles frames, or which path is taken. Instead, they depend on the transport layer to provide the service type they requested, such as reliable stream or best effort message delivery.
At the same time, the transport layer relies on the network layer to deliver its segments to the correct host, and on the lower layers to handle physical transmission. This cooperation between layers allows each to specialize. The transport layer specializes in managing conversations between applications, which is its unique role in the OSI model.