AI Workshop: learn to build apps with AI →
The Internet: The TCP protocol

Join the AI Workshop and learn to build real-world apps with AI. A hands-on, practical program to level up your skills.


TCP means Transmission Control Protocol, and it’s the basis of the Web and other applications like email.

Defined in RFC 793 in 1981, TCP is one of the oldest pillars of the Internet.

TCP sits on top of the Internet Protocol (IP).

Upon it, other application-level protocols like HTTP, FTP, IMAP (and many others) operate.

TCP, contrary to IP and UDP, is connection-oriented.

Before transmission can happen over TCP, a connection must be established. Data is sent in the form of small packets, and when the communication ends, the connection is closed.

When data is transmitted over TCP, there’s a relatively complex workflow called a handshake that must happen.

I will not go into the details here, but this handshake allows the end-to-end connection to happen, and it ensures TCP can provide one of its peculiar features: reliability. Using TCP, we can always know if a packet sent by the sender was received correctly by the receiver.

If a packet gets lost, the protocol is able to handle it and the packet is resent.

On the IP protocol, connections happen from computer to computer. In TCP, a connection happens from process to process, using the concept of ports.

The port, associated with an IP address, allows us to uniquely identify a process on a computer. Like this:

localhost:8080

or

google.com:1234

Each application protocol has a default port. For example, HTTP has 80, HTTPS has 443, and FTP has 21. This is why you don’t usually have to specify the port in the browser.

Programs are not required to use the default. This is why, especially on your local computer, you might see ports like 1313 or 8080 when you start a new application.

Port numbers range from 1 to 65,535 (the port number is a 16-bit unsigned integer, which corresponds to 2^16 possible values).

Lessons in this unit:

0: Introduction
1: What is a URL
2: What is a port
3: The DNS protocol
4: ▶︎ The TCP protocol
5: The UDP protocol