Understanding TCP: The Internet’s Core Protocol for Reliable Data Transfer
This article explains the role of TCP within the Internet protocol stack, details packet size limits, sequence numbering, assembly, slow‑start and ACK mechanisms, and how TCP ensures reliable, ordered data transmission despite packet loss.
TCP is one of the core Internet protocols; this article introduces its basic concepts.
1. Role of the TCP Protocol
The Internet consists of a suite of protocols. TCP occupies one layer with its own responsibilities.
TCP sits above the Ethernet protocol and IP protocol, and below application‑layer protocols.
The lowest layer, Ethernet, defines how electronic signals form packets and enables point‑to‑point communication within a subnet.
Ethernet solves local network communication, but cannot connect multiple LANs; that is handled by the IP protocol.
IP defines its own addressing scheme (IP addresses) and provides routing, allowing a host in one LAN to send messages to a host in another LAN.
Routers, based on IP, connect different LANs. Routers maintain a routing table that maps destination IP ranges to specific interfaces, enabling packet forwarding.
IP only provides addressing and does not guarantee packet integrity. When packets are lost, TCP is responsible for detecting loss and retransmitting.
In short, TCP ensures the completeness and reliability of data communication, preventing packet loss.
2. Size of TCP Packets
Ethernet packets have a fixed size, originally 1518 bytes and later 1522 bytes, with 1500 bytes for payload and 22 bytes for the header.
IP packets reside within the Ethernet payload and have a minimum header of 20 bytes, leaving a maximum IP payload of 1480 bytes.
TCP packets sit inside the IP payload. Their header also requires at least 20 bytes, so the maximum TCP payload is 1480 − 20 = 1460 bytes. In practice, due to additional header options, the usable TCP payload is around 1400 bytes.
Consequently, a 1500‑byte message typically requires two TCP packets. HTTP/2 improves efficiency by compressing HTTP headers so that a single request can fit within one TCP packet.
3. TCP Packet Sequencing (SEQ)
A 1400‑byte packet means large data transfers must be split into many packets; for example, a 10 MB file requires over 7100 packets.
TCP assigns a sequence number (SEQ) to each packet so the receiver can reorder them correctly and detect missing packets.
The first packet’s sequence number is chosen randomly; for illustration we treat it as 1. If the first packet carries 100 bytes, the next packet’s sequence number will be 101, and so on, allowing the receiver to reconstruct the original data.
4. Assembly of TCP Packets
After TCP packets arrive, the operating system reassembles them; applications do not handle raw TCP packets directly.
Applications need not worry about transmission details; they receive complete data unless a line error occurs. Application‑layer protocols (e.g., HTTP) define how data is formatted.
TCP does not convey the original file size; that is provided by the application protocol, such as the HTTP Content‑Length header.
The OS continuously receives TCP packets, orders them, and passes the assembled data to the appropriate application based on the destination port.
For example, a browser reads the Content‑Length field to know how many bytes to read, meaning a single TCP connection can carry multiple HTTP transactions.
5. Slow Start and ACK
Sending data as fast as possible can cause packet loss due to bandwidth limits, router overload, or buffer overflow.
TCP uses a slow‑start mechanism: it begins with a small sending rate and gradually increases it if no packets are lost; otherwise it reduces the rate.
In the Linux kernel, the initial congestion window (TCP_INIT_CWND) is 10 packets. After sending these, the sender waits for acknowledgments before proceeding.
By default, the receiver sends an ACK for every two TCP packets received.
An ACK carries two pieces of information: the next expected packet number and the remaining capacity of the receiver’s window.
Expected next packet number Remaining receive window size
With this information and the latest sent packet number, the sender estimates the receiver’s capacity and adjusts its sending window size accordingly.
Both sides of a TCP connection send ACKs, and their window sizes may differ. ACKs are typically small and often piggybacked on data packets.
Even on high‑bandwidth links, TCP starts with 10 packets and gradually ramps up to the maximum transmission rate; this is the slow‑start phase.
6. Handling Lost Packets
TCP guarantees data integrity by using sequence numbers. If a packet is missing, the ACK number does not advance.
For example, if packet 4 is received but packet 5 is lost, ACKs will repeatedly indicate an expectation for packet 5. When packet 5 finally arrives, the ACK number updates; if later packets arrive before packet 5, the ACK number remains unchanged, leading to duplicate ACKs.
When the sender detects three consecutive duplicate ACKs or a timeout without any ACK, it assumes the packet is lost (e.g., packet 5) and retransmits it, ensuring no data is lost.
7. Reference Links
Network protocols for programmers who know at least one programming language
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.
MaGe Linux Operations
Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.
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.
