Network security

What Is TCP? How the Transmission Control Protocol Works

Almost everything you do online runs over TCP. Here is how it turns a best-effort network into a reliable connection, and where attackers try to break it.

Cysoro Security TeamPublished · 8 min read
CLIENT SERVER SYN SYN-ACK ACK seq 100 · ack 501 · window 64240 NETWORK SECURITY What isTCP? The handshake behind the web.
Quick answer

TCP, the Transmission Control Protocol, is the transport-layer protocol that gives the internet reliable, ordered delivery. It opens a connection with a three-way handshake, numbers every byte, acknowledges what arrives, retransmits what is lost, and controls how fast the sender may send. Most of the web, email and file transfer runs over TCP.

Key takeaways

  • TCP provides a reliable, ordered byte stream on top of IP, which on its own guarantees nothing.
  • A three-way handshake (SYN, SYN-ACK, ACK) opens every connection and agrees starting sequence numbers.
  • Sequence numbers, acknowledgements and retransmission are what make lost or damaged packets invisible to applications.

Every web page you load, every email you send and every file you download travels over TCP. It is the quiet workhorse of the internet: it takes IP, a delivery service that promises nothing, and turns it into a connection your applications can trust.

What is TCP?

TCP, the Transmission Control Protocol, is a transport-layer protocol that provides a reliable, ordered, two-way stream of bytes between two programs on a network. It runs on top of IP and is defined by the IETF in RFC 9293, published in August 2022.

IP on its own is deliberately simple. It moves a packet from one host toward another, but it does not promise the packet will arrive, arrive once, or arrive in the order it was sent. TCP adds the guarantees applications need: every byte arrives, exactly once, in order, or the connection fails loudly instead of delivering corrupted data.

TCP was first standardized in RFC 793 in September 1981, based on work by Vint Cerf and Bob Kahn from 1974. RFC 9293 replaced RFC 793 by gathering four decades of fixes and clarifications into one document. The basic header has not changed since 1981.

TCP is IP protocol number 6. It is connection-oriented, which means the two sides agree on connection state before any data flows, and that state is forgotten when the connection closes.

How does TCP work?

TCP works by numbering every byte, acknowledging what arrives, and retransmitting what does not. The receiver reassembles the stream in order and hands it to the application only when every earlier byte has arrived.

Before any data flows, the two sides open a connection with a three-way handshake. The client sends a SYN segment announcing its initial sequence number. The server replies with a SYN-ACK that announces its own initial sequence number and acknowledges the client's. The client confirms with an ACK, and both sides enter the ESTABLISHED state. The UCLouvain networking textbook walks through the same exchange in detail.

The TCP three-way handshake Client your browser 192.0.2.10:49152 Server web server 203.0.113.80:443 1. SYN seq=100 2. SYN-ACK seq=500, ack=101 3. ACK ack=501 Both sides are now ESTABLISHED — data can flow in both directions. Initial sequence numbers are chosen at random so stale packets cannot be mistaken for live data.
The three-way handshake that opens every TCP connection. Illustration by Cysoro.

Initial sequence numbers are chosen randomly, not from zero. That matters for security: if an old, delayed packet from a dead connection arrives later, a random starting number makes it very unlikely to be accepted as part of the new connection.

During data transfer, the sender tracks which bytes have been acknowledged. If an acknowledgement does not arrive within a timeout, the sender retransmits. The receiver discards duplicates and buffers out-of-order segments until the missing bytes arrive, so the application always reads the stream in the original order.

Closing is a four-step exchange. Each side sends a FIN when it has no more data, and the other side acknowledges it. One side then waits in TIME-WAIT, typically for two minutes, so that any delayed packets from the old connection cannot confuse a new one using the same ports.

Every TCP segment starts with a header that is 20 bytes long when no options are present. The header carries the ports, sequence and acknowledgement numbers, flags and window size that make reliability possible.

The TCP header — 20 bytes, no options Source port (16 bits) Destination port (16 bits) Sequence number (32 bits) Acknowledgement number (32 bits) Data offset Flags: SYN ACK FIN RST Window size A checksum, an urgent pointer and options follow. The data offset says where the payload starts.
Every TCP segment begins with this header. The data follows immediately after it. Illustration by Cysoro.
Header fieldSizeWhat it does
Source port16 bitsIdentifies the sending application
Destination port16 bitsIdentifies the receiving application
Sequence number32 bitsPosition of the first data byte in the stream
Acknowledgement number32 bitsNext byte the sender expects to receive
Flags9 bitsSYN, ACK, FIN, RST and others control the connection
Window size16 bitsHow much data the receiver is ready to accept
Checksum16 bitsDetects corrupted segments so they can be resent

A connection is identified by four values together: source IP, source port, destination IP and destination port. Change any one of them and you have a different connection. That is why your browser can open many tabs to the same website at once: each uses a different local port.

TCP vs UDP: what is the difference?

TCP guarantees reliable, ordered delivery; UDP does not. UDP sends individual datagrams with no handshake, no retransmission and no ordering, which makes it faster but leaves error recovery to the application.

TCPUDP
ConnectionConnection-oriented, three-way handshakeConnectionless, no handshake
ReliabilityGuaranteed delivery with retransmissionBest effort, packets may be lost
OrderingBytes arrive in order, exactly onceDatagrams may arrive out of order or duplicated
SpeedSlower, more overhead per segmentFaster, minimal header (8 bytes)
Flow controlYes, via the receive windowNo
Typical usesWeb, email, file transfer, SSHDNS, live video, voice calls, games

Neither protocol is better in general. TCP is the right choice when correctness matters more than speed, and UDP wins when a late packet is worthless anyway, such as a frame of live video that has already been replaced by the next one.

HTTP/3 is the notable exception to the old rule that the web runs on TCP: it runs over QUIC, which is built on UDP but re-implements reliability, ordering and encryption in the application layer. The idea is the same; the location of the machinery moved.

What is TCP used for?

TCP carries almost everything where correctness matters: web browsing, email, file transfer, remote login and database connections. If losing a byte would corrupt the result, the application almost certainly uses TCP.

ServiceTCP portWhat it carries
HTTPS443Encrypted web traffic
HTTP80Unencrypted web traffic
SSH22Secure remote login and file transfer
SMTP25 / 587Sending email
IMAP143 / 993Reading email from a server
FTP21File transfer
DNS (zone transfers)53Large DNS responses and zone transfers

Ports 0 to 1023 are the well-known system ports, 1024 to 49151 are user ports that IANA can register to applications, and 49152 to 65535 are the ephemeral ports clients use for the local side of a connection. When you visit a website, your computer picks a random ephemeral port and connects to port 443 on the server.

To see the public address your connection comes from, run our what is my IP tool.

To check that a domain resolves and its mail servers answer, use the DNS lookup tool.

How does TCP control flow and congestion?

TCP uses two separate mechanisms: flow control stops a fast sender from overwhelming a slow receiver, and congestion control stops senders from overwhelming the network itself. Both use the same idea — a window that limits how much unacknowledged data can be in flight.

Flow control uses the window field in the header. The receiver advertises how much buffer space it has left, and the sender must not send more than that. If the receiver's application is slow, the window shrinks and the sender slows down.

Congestion control is the sender's own discipline. It starts with a small window and grows it as acknowledgements arrive, a phase called slow start. When packets start being lost, the sender treats that as a sign of congestion and cuts the window back. This probing and backing off is what keeps the internet stable when thousands of senders share the same links.

Modern TCP stacks also use selective acknowledgement (SACK), which lets the receiver say exactly which blocks arrived, so the sender retransmits only the missing pieces instead of everything after the gap. Window scaling lets the 16-bit window field advertise far more than 64 KB, which matters on fast, long-distance links.

What security risks does TCP have?

TCP itself does not encrypt or authenticate anything. Anyone who can see or inject packets can exploit the protocol, which is why TCP almost always needs TLS on top of it for anything sensitive.

The classic attacks are:

  • SYN flooding. An attacker sends a flood of SYN packets and never completes the handshake, leaving the server with a backlog of half-open connections until it stops accepting new ones. SYN cookies let a server answer without storing state for each half-open connection.
  • Sequence number prediction. If an attacker can guess the sequence numbers, they can inject forged segments into a live connection. Random initial sequence numbers, standardized in RFC 1948 and now part of RFC 9293, make guessing impractical.
  • Connection hijacking. An attacker on the path between two hosts can inject data or a RST segment to kill the connection. Encryption with TLS makes injected plaintext useless, because the receiver will reject anything that fails authentication.
  • RST injection. A forged RST segment with the right sequence number tears down a connection. This is how some networks have disrupted connections they disapprove of, and another reason to encrypt.

For a small business, the practical lesson is simple: never run a service in plaintext when an encrypted version exists, and put a firewall in front of any port you expose. Our guide to securing your Wi-Fi covers the home-network side of the same problem.

TCP is not encryptionSeeing a connection on port 443 does not prove it is encrypted — it only proves the port. Check the certificate with our free SSL checker before trusting a site with sensitive data.

How do you check TCP connections on your computer?

Every operating system ships a tool that lists live TCP connections. A quick look tells you which programs are talking to the internet, and to whom.

  1. Windows: open Command Prompt and run netstat -ano. The last column is the process ID, which you can match in Task Manager.
  2. macOS: open Terminal and run netstat -an -p tcp or lsof -iTCP -sTCP:LISTEN to see listening services.
  3. Linux: run ss -t -a in a terminal. It is faster than netstat and shows the same states.
  4. Look for LISTEN entries on ports you do not recognize. A listening port is a service accepting connections, and it should be one you installed on purpose.
  5. Look for ESTABLISHED connections to unfamiliar remote addresses, especially while no browser or app is open. That can be a background updater — or something worth investigating.

States you will see include LISTEN (waiting for a connection), SYN-SENT and SYN-RECEIVED (handshake in progress), ESTABLISHED (data flowing), FIN-WAIT and CLOSE-WAIT (closing), and TIME-WAIT (waiting out delayed packets after closing).

The bottom line

TCP is the reason the internet feels reliable even though the network underneath is not. The handshake, sequence numbers, acknowledgements and retransmission turn lost and reordered packets into a clean stream your applications can trust.

For your own network, the takeaway is practical: prefer encrypted services, keep exposed ports to a minimum, and know how to list the connections your machines are making. You can start by checking your public address with the free what-is-my-IP tool.

Frequently asked questions

What does TCP stand for?

TCP stands for Transmission Control Protocol. It is the transport-layer protocol that provides reliable, ordered delivery of data between two computers on a network, on top of the Internet Protocol (IP).

What is the difference between TCP and IP?

IP moves packets between hosts but guarantees nothing: packets can be lost, duplicated or arrive out of order. TCP sits on top of IP and adds reliability, ordering, flow control and congestion control, so applications see a clean byte stream.

What is the TCP three-way handshake?

The three-way handshake opens a TCP connection in three steps: the client sends a SYN packet, the server replies with SYN-ACK, and the client confirms with ACK. After that, both sides are in the ESTABLISHED state and data can flow.

Is TCP reliable?

Yes. TCP numbers every byte, acknowledges received data, and retransmits anything that is lost or damaged. If the connection cannot recover, TCP reports the failure to the application instead of silently delivering incomplete data.

What port does TCP use?

TCP does not use one port. It uses 16-bit port numbers to identify applications: a connection is defined by the source IP and port plus the destination IP and port. Well-known services include 80 for HTTP, 443 for HTTPS, 25 for SMTP and 22 for SSH.

When should you use TCP instead of UDP?

Use TCP when every byte must arrive, in order, and the application cannot tolerate loss: web pages, email, file transfers and database connections. Use UDP when low latency matters more than completeness, such as live video, voice calls and online games.

How do you check TCP connections on your computer?

On Windows run netstat -an in a command prompt; on macOS and Linux run netstat -an or ss -t in a terminal. Both list every TCP connection, its local and remote address and port, and its state, such as ESTABLISHED or LISTEN.

Sources

  1. IETF — RFC 9293: Transmission Control Protocol (TCP)
  2. UCLouvain — The Transmission Control Protocol
  3. Blowhole — TCP: A Reliable Byte Stream
  4. Semicolony — How TCP Works: Handshake, Sequence Numbers, Reliable Delivery
Written & fact-checked byCysoro Security Team

The engineers and analysts who build Cysoro's domain scanner, email-authentication checks and free security tools. We test what we write about every day — SPF, DKIM, DMARC, certificates, look-alike domains and phishing — and check each guide against the relevant standards, government guidance and vendor documentation.

  • Email authentication
  • Phishing & BEC
  • Domain & DNS security
  • Small-business security

Checked against RFC 9293, the current IETF TCP specification (August 2022), which replaced RFC 793.

How we write and fact-check →

Free tools for this topic

No account needed.

See where your domain stands

Free for up to 3 domains. No card, no installs.

Start free