TCP in plain words
TCP, short for Transmission Control Protocol, is the set of rules computers use to make sure data arrives complete and in order. The network underneath does not promise that. A packet can be lost, delayed, or arrive out of order. TCP checks what arrived, asks for what is missing, and puts the pieces back together before the program sees them.
An analogy
Imagine sending a long letter as a stack of numbered postcards. The receiver notes which numbers arrived and tells you which are missing. You resend those, and the receiver lines the cards up before reading them. TCP does the same job with bytes instead of postcards, and far faster.
The analogy has a limit. TCP also controls how fast it sends, so that it does not flood the network or the receiver.
What TCP does for a program
- Sets up a connection before anything is sent.
- Splits the data into numbered pieces called segments.
- Confirms what arrived.
- Resends what did not arrive.
- Slows down when the network looks congested.
- Closes the connection when both sides are done.
Where TCP fits
When your browser loads a page, the browser hands its request to TCP. TCP splits the request into segments and passes them to IP, which addresses and routes each packet. The network card, whether Ethernet or Wi-Fi, sends the packet on its first hop. The other computer does the same steps in reverse. The browser and mail programs themselves run at the top of this stack, and what is the primary role of the application layer explains that top layer.
Ports: which program gets the data
A computer has one IP address but runs many programs. TCP port numbers direct data to the right one. When you load a secure web page, your browser connects to port 443 on the server, using a temporary port number on your side. The web server software listens on port 443 and answers.
Everyday examples
- Loading a web page over HTTPS uses TCP port 443.
- Sending email usually uses SMTP on port 25 or 587, and reading it over IMAP with TLS uses port 993.
- Logging in to a remote Linux server with SSH uses port 22.
- Downloading a file over HTTPS or SFTP uses TCP as well. SFTP runs over SSH, so it uses port 22.
Why TCP can feel slow
TCP waits for confirmations and resends lost data, so one lost packet can hold up the data that follows it. The handshake also adds a round trip before data flows. That is the price of reliability.
For a live video call or an online game, a late piece of data is often worse than a lost one. Those programs often use UDP instead, which skips the handshake and the resends. Slowness can have other causes too, so what are the 10 common network problems is a wider list to check.
Checking TCP on your computer
On Linux, ss -t lists your TCP connections. On Windows, netstat -ano -p TCP lists them with the program that owns each one. Looking at them is a good way to see what your computer is talking to right now.