How TCP Guarantees Reliable Data Transfer: Packets, Sequencing, and Flow Control Explained
This article provides a comprehensive overview of the TCP protocol, covering its role in the network stack, packet size limits, sequence numbering, how operating systems reassemble packets, the slow‑start mechanism, ACK handling, and strategies for detecting and recovering from lost packets.
1. Role of TCP in the Internet
The Internet is built on layered protocols. Ethernet provides point‑to‑point communication within a LAN, IP supplies addressing and routing across networks, and TCP sits above IP to guarantee reliable end‑to‑end data transfer.
Ethernet defines how electrical signals form packets but cannot interconnect multiple LANs. IP solves this by defining IP addresses and routing tables, enabling hosts in different LANs to communicate.
Routers forward packets based on the destination IP address using their routing tables.
2. TCP Packet Size
Ethernet frames are 1518 bytes (later 1522 bytes). The payload is 1500 bytes and the Ethernet header is 22 bytes.
IP packets reside inside the Ethernet payload and require a minimum 20‑byte IP header, leaving a maximum IP payload of 1480 bytes.
TCP adds its own header (minimum 20 bytes), so the maximum TCP payload is roughly 1460 bytes. In practice, optional headers reduce the usable payload to about 1400 bytes.
A 1500‑byte HTTP request often spans two TCP packets. HTTP/2 compresses header fields, allowing a single request to fit into one TCP packet and thus improving latency.
3. TCP Sequence Numbers (SEQ)
Each TCP segment carries a sequence number (SEQ) so the receiver can reorder packets and detect loss. The first segment starts with a random number; for illustration we treat it as 1.
If a segment contains 100 bytes of data, the next segment’s SEQ will be 101, allowing the receiver to know both the current segment’s position and the start of the following segment.
4. Reassembly of TCP Segments
The operating system reassembles received TCP segments; applications never handle raw TCP packets directly. Once reassembled, data is delivered to the appropriate application based on the destination port (e.g., 21 for FTP, 25 for SMTP, 80 for HTTP).
5. Slow Start and ACK Mechanism
To avoid overwhelming the network, TCP begins with a small congestion window (typically 10 segments, defined by the constant TCP_INIT_CWND in the Linux kernel). The window size grows if no packet loss is detected and shrinks when loss occurs.
The receiver acknowledges received data with ACK packets. By default, an ACK is sent for every two received TCP segments. An ACK carries two pieces of information: the next expected sequence number and the remaining space in the receiver’s window.
Expected next sequence number Remaining receive‑window capacity
6. Handling Lost Packets
If a segment is lost, the receiver continues to send duplicate ACKs indicating the same next‑expected sequence number. When the sender receives three duplicate ACKs (or a timeout occurs), it infers packet loss and retransmits the missing segment.
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.
