Introduction
The transport layer is Layer 4 of the OSI model and sits directly above the network layer. While the network layer (IP) is responsible for getting packets from one host to another across a network, the transport layer takes on a more precise job: delivering data from a specific process on the sending host to a specific process on the receiving host. This is often called process-to-process, or end-to-end, delivery.
Cricket analogy: Just as getting the team bus to the stadium (network layer) is different from getting the ball into a specific fielder's hands (transport layer), IP delivers to the host while the transport layer delivers to the exact process.
Explanation
A single computer can run many applications at once - a web browser, an email client, a music streaming app - all sharing the same network connection. IP only gets data as far as the correct machine; it has no concept of which application on that machine should receive it. The transport layer solves this using port numbers, which identify individual processes, combined with the concept of a socket (an IP address plus a port). The two dominant transport-layer protocols are TCP (Transmission Control Protocol) and UDP (User Datagram Protocol), which take very different approaches to delivering data but both rely on this same addressing model.
Cricket analogy: A stadium (IP address) hosts many activities at once, nets practice, a match, media interviews, so gate numbers (ports) direct each visitor to the right area, just as TCP and UDP use port numbers to reach the right app.
Beyond addressing individual processes, the transport layer also provides services that the network layer does not guarantee, such as reliability, ordering, and flow/congestion control (in TCP's case), or a lightweight, low-overhead path for applications that can tolerate loss (in UDP's case). It also performs segmentation - breaking application data into smaller units, called segments (TCP) or datagrams (UDP), that fit within the limits imposed by lower layers - and reassembly on the receiving end.
Cricket analogy: TCP is like a Test match innings insisting every ball is bowled in strict order with no dropped deliveries, while UDP is like a quick exhibition six-hitting contest that tolerates a missed swing; both segment the game into overs for delivery.
Example
import socket
# A simple TCP client illustrating process-to-process delivery.
# The destination is identified by BOTH an IP address (which host)
# and a port number (which process/service on that host).
HOST = "93.184.216.34" # example.com's IP
PORT = 80 # the HTTP server process listens here
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.connect((HOST, PORT))
s.sendall(b"GET / HTTP/1.1\r\nHost: example.com\r\n\r\n")
response = s.recv(4096)
print(response[:100])Analysis
In the example, the network layer's job ends once the packet reaches the machine at 93.184.216.34. It is the transport layer, using port 80, that hands the data to the correct process - the web server - rather than to some other application also running on that machine. This division of labor is what allows the network layer to stay simple and focused on routing, while the transport layer handles multiplexing multiple application conversations over a single network path and, in TCP's case, provides reliability guarantees the network layer does not offer.
Cricket analogy: Once the team bus reaches the stadium gate at address 93.184.216.34, that's the network layer's job done, but it's the gate number (port 80) that gets you specifically to the players' entrance, not the media or VIP gate.
Key Takeaways
- The transport layer provides process-to-process (end-to-end) delivery, distinct from the network layer's host-to-host delivery.
- Ports identify individual application processes on a host; a socket is the combination of an IP address and a port.
- TCP and UDP are the two main transport-layer protocols, offering very different trade-offs.
- The transport layer segments application data for transmission and reassembles it on arrival.
- Services like reliability, ordering, flow control, and congestion control are implemented at this layer, not the network layer.
Practice what you learned
1. What is the primary responsibility of the transport layer that distinguishes it from the network layer?
2. Which of the following uniquely identifies an application process on a networked host?
3. What are the two dominant transport-layer protocols?
4. What does the transport layer do to application data before handing it to the network layer?
Was this page helpful?
You May Also Like
TCP vs UDP
Compare TCP and UDP across reliability, ordering, connection state, overhead, and typical use cases.
Ports and Sockets
Understand port number ranges and how a socket, the pairing of an IP address and port, identifies a network endpoint.
Network Layer Basics
Learn how the network layer handles logical addressing, packet forwarding, and fragmentation to move data across networks.
The OSI Model
Understand the 7 layers of the OSI reference model, their responsibilities, and example protocols at each layer.