What is TCP (Transmission Control Protocol)?
Updated: Oct 27

TCP, or Transmission Control Protocol, is a transport protocol that gives applications a reliable, ordered stream of bytes between two endpoints over IP. It uses sequence numbers, acknowledgements and retransmission to recover missing data, while flow control and congestion control limit how much data can be outstanding. Applications still need to define their messages and decide what counts as successful work.
TCP supports everyday tasks such as file transfers, email and many web connections. Its recovery mechanisms help keep data complete, but they can add waiting when the network loses traffic. TCP does not encrypt a connection by itself, guarantee that a remote application has saved your data, or make every transfer reach a broadband package’s advertised speed.
What TCP provides, and where it fits
IP carries packets between network addresses. TCP operates above IP and uses ports to help distinguish application endpoints. An ordinary connection is identified by the combination of local and remote addresses and ports. Each end maintains state for the conversation, including sequence information, buffers and transmission limits.
The service is full duplex: both endpoints can send data. It is also a byte stream rather than a message service. An application may write several records, but the receiving application needs its own rules to recognise where each record ends. A length field, a delimiter or a protocol-defined structure can provide those rules.
The IETF’s TCP specification, RFC 9293, became Internet Standard STD 7 in August 2022 and replaced RFC 793 as the consolidated core description. TCP also has separate specifications for important extensions and algorithms. A diagram of the basic header is therefore only a starting point for understanding a real implementation.
TCP sits below application protocols. HTTP/1.1 and HTTP/2 commonly use TCP, often with TLS for security. HTTP/3 uses QUIC instead. It is inaccurate to use “TCP” as another name for the whole internet, or to assume that all web traffic must follow the same transport path.
The fields that make an ordered stream possible
A basic TCP header is 20 bytes before any TCP options. It accompanies application data inside an IP packet. The actual overhead depends on options, IP headers and other encapsulation, so 20 bytes is not a universal allowance for the entire packet.
Header information | What it contributes |
|---|---|
Source and destination ports | Identify the transport endpoints used by the conversation. |
Sequence number | Locates data within one direction’s byte sequence. |
Acknowledgement number | Reports the next sequence position expected, cumulatively acknowledging earlier bytes. |
Window | Advertises a receive-side limit; negotiated scaling can enlarge its effective value. |
Control flags and checksum | Support connection management and error detection; neither supplies application encryption. |
The two directions have separate sequence spaces. A number attached to data sent by a client is not a global packet number shared with the server. TCP sequence arithmetic also wraps in its finite number space; the small examples here avoid that boundary so the mechanism is easier to follow.
How the ordinary three-way handshake works
Before normal data transfer on a new ordinary connection, TCP synchronises initial sequence information. In a simplified example, the client sends SYN with sequence 1000. The server returns SYN plus ACK with its own sequence 5000 and acknowledgement 1001. The client then acknowledges 5001.
SYN consumes one sequence position, which explains the additions of one. After this exchange, the client’s first data byte can start at 1001 and the server’s at 5001. These are illustrative numbers, not values captured from a live connection. Real initial sequence selection has security requirements.
The handshake establishes transport state; it does not authenticate the server’s identity or demonstrate that a database operation has succeeded. TLS and the application protocol perform different jobs. Reusing a suitable existing connection can avoid repeatedly paying for new connection setup, although idle policies and service requirements still apply.
The familiar three arrows describe the ordinary case, not every possible TCP opening. Simultaneous opening and specialised mechanisms exist. RFC 7413 describes TCP Fast Open as an Experimental mechanism that can carry data during opening, with replay considerations for applications. It should not be treated as universally enabled behaviour.
Sequence numbers, gaps and acknowledgements
Consider an established connection whose next data byte is 1001. A segment carries 100 bytes, covering 1001 through 1100. If those bytes arrive contiguously, an acknowledgement of 1101 means that the receiver expects byte 1101 next. It does not mean “packet 1101 arrived”.
Now suppose bytes 1101 through 1200 are missing, while bytes 1201 through 1300 arrive. The cumulative acknowledgement cannot advance past the gap merely because later data is present. A receiver may buffer that later range, while the sending endpoint uses feedback and timers to decide what needs recovery.
Once the missing 100-byte range arrives and the whole range is contiguous, the cumulative acknowledgement can advance to 1301. The receiving application can then obtain the ordered stream. This creates a practical trade-off: recovery preserves order, but data after a gap may have to wait even if it has already reached the receiver.
Selective Acknowledgement, or SACK, lets a supporting receiver report additional received byte ranges. That gives the sender more detail than a cumulative acknowledgement alone. It does not turn the connection into separate independently deliverable application messages.
Loss detection is more than counting three duplicate ACKs
Classic TCP explanations often concentrate on duplicate acknowledgements and fast retransmit. Those mechanisms are useful context, but they are not a complete description of every current stack. RFC 8985 specifies RACK-TLP, which uses transmission timing and selective acknowledgement feedback to infer loss and can probe the tail of a transfer.
Retransmission timers are another part of recovery. RFC 6298 describes estimating a retransmission timeout from round-trip observations and backing it off after expiration. The timer is not simply the application’s deadline. A connection can remain involved in recovery after an application has decided that a result is too late to use.
The Packet Loss guide explains why loss and delay need separate measurements. TCP can hide some missing packets from the application by retransmitting their data, while the user experiences a pause or lower throughput. A completed file transfer therefore does not prove the route experienced no loss.
What our local TCP socket check showed
Techie Broadband ran a small Python 3.12.14 check on Linux using IPv4 TCP sockets bound to 127.0.0.1 and automatically allocated ports. Every socket and listener was closed afterwards. As the Loopback Address guide explains, this traffic stayed on one computer; it did not traverse a router or UK broadband line.
The client made two writes containing one and second!, three and seven bytes respectively. The server asked for at most four bytes per read. In this run, it received one, then seco, then nd!, which joined into onesecond!. The receiving program’s read boundaries did not preserve the client’s two original writes.
A second exchange added a two-byte length field before each record. The encoded stream contained 14 bytes: two length fields plus ten payload bytes. The server deliberately read one byte at a time and used the length values to reconstruct the original two records. That framing came from our application code, rather than a TCP record feature.
Local check | Observed result and limitation |
|---|---|
Two writes; reads limited to four bytes | Three reads returned one, seco and nd!. Other runs may divide the stream differently. |
Two-byte record lengths; one-byte reads | The parser recovered one and second! from a 14-byte stream. This tested framing, not network packet sizes. |
Client finished sending, then waited | The server received end-of-stream and sent confirmed-after-EOF, which the client received. |
For the last check, the client shut down only its sending direction after its writes. The server read until end-of-stream, then sent its reply. This demonstrated a useful half-close pattern in the selected socket API. It was not a packet capture of FIN flags, a measurement of retransmissions or a throughput benchmark.
The important programming consequence is to keep reading and parsing according to the application protocol. A successful send call reports local acceptance under the API’s rules. It does not prove that the receiving application has read a complete request, validated it or committed the requested change.
Flow control and congestion control solve different problems
Flow control protects the receiving endpoint from being overwhelmed. Its advertised receive window, often written rwnd, reflects how much incoming data the receiver is prepared to accept under TCP’s window rules. A slow application can leave less room available even on an otherwise fast path.
Congestion control limits the sender’s pressure on the network. The congestion window, cwnd, is maintained by the sender. Feedback about delivery, congestion and loss influences how it evolves. The network does not advertise cwnd in the TCP window field.
RFC 5681 describes the baseline relationship: the smaller of cwnd and rwnd governs the amount of data that may be outstanding. For example, with cwnd of 64,000 bytes and rwnd of 256,000 bytes, the governing limit is 64,000 bytes. If 40,000 bytes are already in flight, the remaining allowance is only 24,000 bytes, subject to the other transmission rules.
These are byte limits, not speeds in Mbps. Pacing, available data, acknowledgements and the path also affect when data is sent. Increasing a receiver buffer cannot remove a congestion-window constraint, and increasing a sending limit cannot make a slow receiver consume data faster.
Slow start probes capacity early in a transfer rather than immediately assuming a large sending allowance. Congestion avoidance and recovery then manage continued transmission. The standard CUBIC specification, RFC 9438, published in August 2023, updates the older congestion-control specification. It is a reminder that a single textbook growth curve does not describe every implementation or every transfer.

Why bandwidth and round-trip time both matter
A sender needs enough data outstanding to keep a path busy while waiting for feedback. The bandwidth-delay product gives a useful scale for that pipeline. It does not guarantee throughput, but it explains why a small allowed flight of data can restrict a single TCP connection even when the access line has spare capacity.
Our worked example assumes a constant 100 Mbps path and a 40 ms round-trip time. Using decimal units, 100,000,000 bits per second multiplied by 0.040 seconds equals 4,000,000 bits, or 500,000 bytes. That is the approximate amount of data needed in flight to fill this illustrative pipeline.
If an effective outstanding-data limit were instead 100,000 bytes, dividing by 0.040 seconds gives 2,500,000 bytes per second, or 20 Mbps. This is an ideal window-and-RTT upper-bound calculation. It excludes protocol overhead, startup, losses, scheduling and other bottlenecks; it is not a prediction of an actual UK service.
Illustrative quantity | Calculation or meaning |
|---|---|
100 Mbps and 40 ms RTT | 100,000,000 × 0.040 ÷ 8 = 500,000 bytes in the pipeline. |
100,000-byte effective window at 40 ms | 100,000 × 8 ÷ 0.040 = 20,000,000 bits/s, or 20 Mbps. |
Interpretation | A small window can limit one flow; adequate windows alone do not guarantee the path rate. |
The Window Scale specification, RFC 7323, explains how TCP can negotiate larger receive windows during connection opening. Scaling affects the advertised receive window; it is not a setting that increases the broadband line’s capacity. Actual buffer management and negotiated capabilities depend on the endpoints.
Our Bandwidth guide separates available capacity from achieved throughput. A multi-connection speed test and one file transfer can exercise different servers, paths and numbers of flows. A faster result from one test does not identify which TCP parameter, if any, explains the other result.
Closing, idle connections and application success
A normal FIN indicates that an endpoint has finished sending in that direction. The other direction can still carry data, as our local check illustrated. Closure and acknowledgements can be combined in different ways, so every close should not be described as a mandatory four-packet exchange. A reset, RST, is an abort rather than a normal promise to finish the conversation.
An apparently established idle connection is not proof that the remote application remains healthy. TCP keep-alive support and policy are separate from an application heartbeat. A transport peer can respond while the service behind it is stalled, and an intermediary can expire its own state while an endpoint still believes a connection exists.
For meaningful success, use the application’s response and its documented semantics. A TCP acknowledgement covers received transport bytes. It is not an invoice receipt, a transaction commit or evidence that a file has been durably stored. After an ambiguous interruption, retries may need an operation identifier or another application-level way to avoid duplicate work.
TCP, UDP, QUIC and encryption
The UDP guide describes a different basic service: independent datagrams with no built-in promise of ordered recovery. TCP supplies those recovery and ordering mechanisms for a byte stream. Neither interface is automatically best for every workload; the application’s tolerance for missing, late or reordered data matters.
Use a reliable stream when the application needs complete ordered bytes and can accommodate recovery delays.
Use datagram-based designs only with a clear plan for acceptable loss, congestion behaviour, message size and security.
Remember that QUIC builds reliable streams and other transport mechanisms above UDP; UDP-based traffic is not necessarily unreliable at the application interface.
Assess the actual protocol and implementation instead of assuming TCP is always slow or UDP is always fast.
Basic TCP provides neither encryption nor cryptographic peer authentication. TLS is commonly used above TCP to protect application exchanges, with TLS 1.3 specified in RFC 8446. A TCP checksum detects certain transmission errors; it is not a substitute for a secure protocol or certificate validation.
A practical TCP troubleshooting sequence
For a slow or failing transfer, work from the application outwards. Record whether the failure happens during name lookup, connection opening, security negotiation, request processing or sustained data transfer. Those stages can produce similar-looking symptoms for different reasons.
Confirm the intended hostname, address, service and application error. Compare another known-working request without changing security settings.
Test a suitable wired connection and a second device where practical. Keep the destination and test method consistent.
Compare quiet conditions with controlled download and upload load. Record round-trip time as well as throughput.
Separate connection-opening failure from a connection that opens but stalls. Review endpoint logs and authorised packet or transport counters when available.
Check receiver and server limits, retransmission evidence, window constraints and path MTU where symptoms justify it. A single reset or retransmission does not identify the responsible device.
Retest after one relevant change and confirm application-level completion. Preserve timestamps and concise evidence for the service operator or ISP.
Latency under load is especially useful when transfers slow down while other traffic is busy. A download also depends on feedback returning upstream; congestion and queues in either direction can influence progress. That does not mean every slow download is caused by insufficient upload capacity.
An ICMP ping and a successful TCP connection test different traffic and processing paths. Avoid inferring that an entire route is healthy from one successful probe. Likewise, do not disable a firewall or apply random buffer and registry changes simply because a speed test and an application disagree.
Frequently asked questions
Does TCP guarantee that data will arrive?
TCP provides recovery and ordered delivery while a connection can make progress. Persistent failures can still terminate it. A successful transport acknowledgement also does not prove that the remote application completed or saved the requested work.
Does one TCP write equal one received message?
No. TCP exposes a byte stream, and receiving reads can split or combine data differently. The application protocol needs framing, such as lengths or delimiters, to identify its records.
Is TCP encrypted?
Basic TCP is not encrypted. Applications commonly use TLS or another appropriate security layer; the TCP checksum is an error-detection mechanism rather than cryptographic protection.
Why can a TCP transfer be slower than a speed test?
The transfer may use a different server, route, flow count or application workload. Round-trip time, recovery, endpoint limits and window constraints can also matter. The difference alone does not prove a broadband fault or a particular TCP misconfiguration.
What to remember
TCP makes an ordered stream practical over a network that can lose or reorder packets. Its real value comes from sequence tracking, recovery and controlled transmission, with application framing and meaningful success checks above it. Diagnosing performance means examining that complete chain rather than treating a handshake, an acknowledgement or a high line rate as the whole answer.

