Understanding TCP vs UDP: Reliable and Unreliable Transport Explained
This article provides a comprehensive overview of the transport layer, explaining how TCP and UDP differ in reliability, connection management, port usage, handshake processes, sequence numbers, acknowledgments, retransmission, window and flow control, as well as congestion handling.
Transport Layer Overview
The transport layer provides end‑to‑end communication between applications. It offers two core protocols: TCP (connection‑oriented, reliable) and UDP (connection‑less, unreliable).
IP Addresses and Port Numbers
An IP address identifies a host. The IP header contains a protocol field (6 for TCP, 17 for UDP) that indicates which transport protocol carries the payload. To differentiate multiple applications on the same host, the transport layer uses 16‑bit port numbers , often called program addresses .
Port Number Ranges
Well‑known ports (0‑1023) – reserved for standard services (e.g., HTTP 80, SSH 22).
Registered ports (1024‑49151) – assigned to specific applications.
Dynamic (private) ports (49152‑65535) – allocated by the operating system for client connections.
TCP vs UDP
TCP delivers a reliable byte‑stream. It provides sequence control, acknowledgments, retransmission, flow control, congestion control, and optional extensions. UDP delivers datagrams without guaranteeing delivery, order, or congestion control; applications must implement any required reliability.
Key Differences
TCP establishes a connection with a three‑way handshake, uses ACKs, and retransmits lost segments.
UDP has lower overhead and is suited for DNS, video/audio streaming, LAN‑only services, and broadcast/multicast.
TCP Connection Management
TCP creates a connection using a three‑way handshake:
SYN: client sends a SYN segment with initial sequence number a.
SYN‑ACK: server replies with SYN and ACK, sequence b, acknowledgment a+1.
ACK: client acknowledges with ACK, sequence a+1, acknowledgment b+1. Data transfer can then begin.
Connection termination uses a four‑step handshake (FIN/ACK exchange) to close both directions.
Sequence Numbers and Acknowledgments
Each TCP segment carries a 32‑bit sequence number. The receiver returns an ACK indicating the next expected sequence number (N+1 means all bytes up to N were received). Duplicate ACKs trigger fast retransmission.
Timeout Retransmission
If an ACK is not received within the measured round‑trip time (RTT), the sender retransmits the segment. Retransmission intervals double exponentially until a limit is reached, after which the connection is aborted.
Window and Flow Control
TCP uses a sliding window to allow multiple unacknowledged segments. The 16‑bit window field specifies how many bytes the receiver can accept. A zero window signals that the receiver’s buffer is full, prompting the sender to pause. The receiver advertises its available buffer size; the sender must not exceed this advertised window, preventing buffer overflow.
Congestion Control
TCP employs slow start: the congestion window (cwnd) starts at one maximum‑segment‑size (MSS) and grows by one MSS for each ACK received until loss is detected. This limits the amount of data injected into the network, avoiding congestion collapse.
UDP Header Format
UDP has a fixed 8‑byte header followed by payload data. The header fields are:
Source port (16 bits)
Destination port (16 bits)
Length (16 bits) – total length of header and data
Checksum (16 bits) – optional error‑checking field
TCP Header Format
TCP’s header consists of a mandatory 20‑byte portion plus optional fields. Key fields include:
Source port (16 bits)
Destination port (16 bits)
Sequence number (32 bits)
Acknowledgment number (32 bits)
Data offset (4 bits) – header length
Reserved (6 bits)
Control flags (6 bits): URG, ACK, PSH, RST, SYN, FIN
Window size (16 bits) – receiver’s advertised buffer
Checksum (16 bits)
Urgent pointer (16 bits) – valid if URG is set
Options (variable length) – e.g., MSS, window scaling
Additional TCP Mechanisms
Maximum Segment Size (MSS)
During the three‑way handshake each side advertises its MSS. The smaller value is used for segment sizing. Typical defaults are 536 bytes (minimum) and 1460 bytes (optimal for Ethernet with a 1500‑byte MTU).
Fast Retransmit and Fast Recovery
When the sender receives three duplicate ACKs, it performs a fast retransmit of the missing segment without waiting for the retransmission timer. The congestion window is then reduced (typically to half) and grows again using additive increase.
Window Probing
If the advertised window is zero, the sender may send a one‑byte “window probe” to elicit an updated window size from the receiver.
Summary of Differences
TCP provides reliable, ordered delivery with flow and congestion control; suitable for applications that require data integrity (e.g., web, file transfer).
UDP provides low‑latency, connection‑less delivery without reliability guarantees; suitable for latency‑sensitive or broadcast applications (e.g., DNS, VoIP, streaming).
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Liangxu Linux
Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
