What is TCP?
Author: Domeny.ForSale editorial team Published
In brief: TCP is a transport protocol: a set of rules for transferring data between applications running on a network. It ensures that data is delivered in the correct order, detects missing data and retransmits lost portions. However, it does not guarantee that every connection will succeed, nor does it encrypt the information being transmitted.
What role does TCP play on the internet?
TCP, short for Transmission Control Protocol, operates between applications and the layer responsible for sending packets across the network. It is used by email, remote login via SSH and many connections to websites, among other things. Thanks to TCP, an application does not have to keep track of the order of data fragments or resend them after they are lost.
TCP often appears alongside the abbreviation IP, but these protocols have different jobs. IP handles addressing and sending packets between devices; it does not ensure their delivery or correct order. TCP adds the mechanisms needed to reliably transfer an ordered byte stream: a sequence of data read by an application.
You can compare this to sending numbered parts of a document. IP helps direct the shipments to the recipient, while TCP keeps track of numbering, acknowledgements and resending missing parts. This is a simplification: in reality, TCP numbers bytes, not document pages.
How does TCP establish a connection and transfer data?
Before a normal exchange of data begins, TCP establishes a connection. The basic procedure consists of three steps, known as the three-way handshake:
- The client sends a SYN message, proposing that a connection be established.
- The server responds with SYN-ACK, acknowledging the proposal and supplying its own initial parameters.
- The client sends ACK, acknowledging the server’s response.
During this handshake, both sides establish initial sequence numbers, among other things, allowing them to track the position of data in the stream. Establishing a connection does not in itself mean that a user has logged in or that the server’s identity has been verified.
Data is then sent in segments: portions containing a fragment of data and TCP control information. The receiver acknowledges the data received, and the sender detects probable losses based on acknowledgements or elapsed time. It sends missing data again—this is retransmission.
If segments arrive out of order, TCP puts them in order before making the data available to the application. It also handles duplication so that the application does not read the same bytes twice. If a failure persists for too long, the connection may be terminated rather than successfully delivering all the data.
What does TCP provide, and what does it not do?
Besides keeping data in order, TCP regulates the transmission rate. Flow control protects the receiver from an influx of more data than it can accept at a given moment. Congestion control adjusts transmission to network conditions, reducing pressure on congested links.
TCP also includes a checksum that helps detect accidental corruption of segments. However, this is not cryptographic protection against deliberate modification. Encryption and authentication are provided by other mechanisms, such as TLS, which is used in HTTPS.
Two further limitations are important:
- TCP does not preserve message boundaries. If an application sends two messages, the receiver may read them together or in several parts. The application protocol must define where each message ends.
- A TCP acknowledgement does not mean an operation has been completed. Receipt of data by the server’s TCP layer does not prove that a shop has saved an order or a system has recorded a payment. That requires a response from the application.
For example, if a connection drops while you are placing an order, the TCP error alone cannot tell you whether the order was created. Before repeating the operation, check its status in the shop rather than assuming that the data did not arrive.
How does TCP differ from UDP?
UDP is another transport protocol. It sends independent messages, called datagrams, without built-in acknowledgements, retransmission or ordering. An application can add these mechanisms, but UDP itself does not provide them.
| Feature | TCP | UDP |
|---|---|---|
| Transfer method | Ordered byte stream | Separate datagrams |
| Retransmission of lost data | Built in | Depends on the application |
| Connection establishment | Required | No such procedure in UDP |
| Typical application priority | Data completeness and order | Application control over latency and losses |
When downloading a file, a missing portion needs to be supplied, so TCP’s mechanisms are useful. During a voice call, a late fragment of audio may be less useful than simply leaving a short gap. This is why real-time solutions often use UDP.
This does not mean that UDP is always faster or that every website uses TCP. HTTP/1.1 and HTTP/2 usually run over TCP, while HTTP/3 uses QUIC, which is based on UDP. QUIC itself provides reliable stream transfer and encryption, among other things.
What does a TCP port mean in network settings?
A port is a number that helps the system direct traffic to the correct service. An IP address identifies a point on the network, while a port distinguishes between services available at that address. A typical example is TCP port 443, used by HTTPS over TCP.
TCP and UDP have separate port namespaces. A firewall rule allowing TCP 443 does not automatically allow UDP 443, which HTTP/3 often uses. An open port alone also does not prove that an application is working correctly or securely.
If you are configuring a firewall, check the documentation for the specific service to find the required protocol, port number and traffic direction. This will let you create a precise rule instead of unnecessarily allowing all TCP and UDP traffic.
