The transport layer provides end-to-end communication services between processes on different hosts. Two protocols dominate: TCP (reliable, connection-oriented, byte-stream) and UDP (unreliable, Connectionless, datagram). Understanding the trade-offs between them, and how TCP achieves Reliability over an unreliable network, is fundamental to systems engineering.
The transport layer is the first layer where the concept of a “connection” exists (for TCP). The Network layer (IP) delivers individual packets with no guarantees. The transport layer builds on This unreliable foundation to provide the reliability that applications need.
The transport layer is also where multiplexing happens. Multiple applications on the same host Can communicate over the network simultaneously because the transport layer uses port numbers to Demultiplex incoming packets to the correct application socket. This is why you can run a web server (port 80), a database (port 5432), and an SSH daemon (port 22) on the same machine simultaneously.
The socket API is the standard interface for transport-layer communication. Defined in BSD Unix in The early 1980s, it provides a uniform interface for TCP, UDP, and other transport protocols. The Socket API is the de facto standard across all operating systems.
UDP (RFC 768) is the simplest transport protocol. It provides a minimal interface: applications send And receive datagrams with no guarantees of delivery, ordering, or duplicate suppression.
Source Port (16 bits): Optional. Identifies the sending process. If zero, the receiver should not respond.
Destination Port (16 bits): Required. Identifies the receiving process.
Length (16 bits): Total length of the UDP header and data. Minimum is 8 (header only).
Checksum (16 bits): Optional in IPv4 (zero means “not computed”), mandatory in IPv6. Covers the UDP header, data, and a pseudo-header (source/destination IP, protocol number, length). The pseudo-header binds the UDP checksum to specific IP endpoints, preventing a misdirected datagram from being accepted.
Connectionless: No handshake. No connection state on either endpoint. The sender creates a datagram and sends it. The receiver gets it or does not. There is no setup or teardown.
Unreliable: No acknowledgments, no retransmissions. Datagrams may be lost, duplicated, or arrive out of order. The application is responsible for handling these cases if needed.
Message-oriented: Each sendto() call produces exactly one datagram. The receiver gets the exact message boundaries. This is fundamentally different from TCP”s byte-stream model.
No flow control: If the receiver cannot keep up, datagrams are silently dropped. The kernel’s receive buffer fills up, and new datagrams are discarded. ss -uanp shows the receive queue depth.
No congestion control: UDP sends as fast as the application produces data, which can cause packet loss on congested networks. This is why UDP-based protocols that send at high rates (e.g., video streaming, VPNs) must implement their own congestion control.
Low overhead: 8-byte header vs 20-byte minimum for TCP. No connection establishment or teardown latency. A single UDP datagram requires one packet in each direction, compared to TCP’s three-way handshake (3 packets) plus data transfer.
The theoretical maximum UDP payload is 65,527 bytes (65,535 total minus 8-byte header). In practice:
IPv4: The payload must fit within the path MTU minus IP header (20 bytes) and UDP header (8 bytes). Over standard Ethernet, the safe maximum is 1500−20−8=1472 bytes. Larger datagrams are fragmented by the source. Fragmented UDP is unreliable — if any fragment is lost, the entire datagram is lost.
IPv6: IPv6 requires the source to perform Path MTU Discovery. Fragmentation is only performed by the source, not by routers. This means UDP over IPv6 has stricter size limits and may fail differently than over IPv4.
Practical limit: Many implementations cap UDP buffers at 8192 or 9216 bytes. Applications that need to send more should implement their own fragmentation.
Low latency matters more than reliability. Real-time audio/video, gaming, and live streaming use UDP because retransmitting a late packet makes it later. A dropped video frame is acceptable; a delayed video frame causes stuttering.
The application implements its own reliability. QUIC, WebRTC, and DNS (over TCP for zone transfers) implement reliability at the application layer, using UDP as a substrate. QUIC adds congestion control, reliability, and ordering on top of UDP.
Multicast/broadcast delivery is required. UDP supports multicast and broadcast addressing. TCP does not. Streaming protocols (IPTV), discovery protocols (mDNS, SSDP), and financial market data feeds use UDP multicast.
Simple request-response with small payloads. DNS queries, NTP, and SNMP use UDP because the overhead of TCP (3-way handshake, 20-byte header) is disproportionate for small exchanges. A DNS query is under 100 bytes; TCP’s 60-byte minimum overhead for connection setup is wasteful.
Head-of-line blocking is unacceptable. TCP’s ordered delivery means one lost packet blocks delivery of all subsequent packets. UDP allows the receiver to process newer data while waiting for retransmissions.
TCP and UDP are the two main transport protocols. TCP is the reliable courier: it tracks every packet, retransmits lost ones, and delivers data in order. UDP is the fast messenger: it sends packets without waiting for confirmation, trading reliability for speed. TCP is used for web browsing, email, and file transfers where every byte matters. UDP is used for video streaming, gaming, and DNS where speed matters more than perfect delivery.