# TCP (Transmission Control Protocol)

URL: https://softwaredictionary.org/terms/tcp
Category: Networking
Last updated: 2026-09-30

In short: TCP is a core internet protocol that delivers data between two programs reliably and in order, by opening a connection and resending anything that gets lost.

## What is TCP?

TCP, the Transmission Control Protocol, is one of the main protocols of the internet. It creates a reliable connection between two programs, such as a browser and a web server, and guarantees that the bytes sent by one side arrive at the other complete, uncorrupted, and in the same order. TCP runs on top of IP: IP moves individual packets between machines, and TCP turns them into a dependable stream of data.

A TCP connection starts with a three-way handshake: the client sends `SYN`, the server replies with `SYN-ACK`, and the client answers with `ACK`. After that, data is split into numbered segments, and the receiver sends acknowledgments for what it has received. If a segment is not acknowledged in time, the sender retransmits it, while flow control and congestion control slow the sender down when the receiver or the network is overloaded.

A good analogy is a phone call. You first connect, then speak in order, and the other person can ask you to repeat anything they missed. TCP carries most traffic that must arrive exactly as sent, including web pages over HTTP/1.1 and HTTP/2, email, file transfers, SSH sessions, and database connections.

TCP is most often compared with UDP. UDP sends independent packets with no connection, no ordering, and no retransmission, which makes it faster and lighter but unreliable. Choose TCP when every byte must arrive correctly, and UDP when speed matters more than perfection, as in live video calls or online games.

## Key takeaways

- TCP is connection-oriented: it opens a connection with a three-way handshake before sending data.
- It guarantees delivery, correct order, and error checking using sequence numbers and acknowledgments.
- Lost data is detected and retransmitted automatically.
- Flow control and congestion control keep the sender from overwhelming the receiver or the network.
- The trade-off is extra overhead and latency compared with UDP.

## Example: Opening a TCP connection in Python

```python
import socket

# Open a TCP connection to a web server on port 80
with socket.create_connection(("example.com", 80)) as sock:
    # Send a minimal HTTP request over the TCP stream
    sock.sendall(b"GET / HTTP/1.1\r\nHost: example.com\r\nConnection: close\r\n\r\n")

    # TCP delivers the reply bytes reliably and in order
    reply = sock.recv(1024)
    print(reply.decode(errors="replace").splitlines()[0])  # e.g. HTTP/1.1 200 OK
```

## Frequently asked questions

**What is the difference between TCP and UDP?**

TCP sets up a connection and guarantees that data arrives complete and in order, resending anything lost. UDP just sends packets with no connection or guarantees, which is faster but means some data may be lost or arrive out of order.

**What is the TCP three-way handshake?**

It is how a TCP connection starts: the client sends a `SYN` message, the server replies with `SYN-ACK`, and the client confirms with `ACK`. After these three steps, both sides have agreed on starting sequence numbers and can exchange data.

**Does HTTP use TCP?**

HTTP/1.1 and HTTP/2 run over TCP, usually with TLS on top for HTTPS. HTTP/3 instead runs over QUIC, a newer protocol built on UDP that adds its own reliability and encryption.

## Sources

- [RFC 9293: Transmission Control Protocol (TCP)](https://www.rfc-editor.org/rfc/rfc9293.html)

---

Software Dictionary: https://softwaredictionary.org/ · https://softwaredictionary.org/llms.txt
