Do you ever wonder how the internet works? How from the comfort of your home you can send and receive pictures, emails, calls, and view websites from your device connected to the internet? These actions depend on TCP and UDP ports. How do these ports work, and what are they?

Before delving into the topic, you must understand what a port is. Computers use ports to communicate and form connections with other computers on a network. The port in question here is not a physical component but a virtual endpoint between two or more computers. The most common ports on the internet are the TCP and UDP ports.

What Are TCP Ports?

TCP stands for Transmission Control Protocol, and it is a connection-oriented protocol. In networking, protocols are rules or standards that govern how data is transmitted between devices. TCP is called a connection-oriented protocol because it establishes a connection between the receiving and sending devices before transmitting any data.

TCP ports are ports that comply with the transmission control protocols. Some TCP ports include File Transfer Protocol ports (20 and 21) for file transfers, the SMTP port (25) and IMAP port (143) for emails, and the Secure Shell port (22).

How Do TCP Ports Work?

TCP ports create connections before data is shared. For instance, if you want to tell your friend about a new movie or game, you can make a phone call. You dial your friend's number, and if she gets the call and confirms that you are on the other end of the line, she picks up. Then you can begin to tell her about the game.

That's how TCP ports work, too. A secure connection between the sender and receiving device is ensured before transmitting data. But how do devices using the TCP ports to receive or send data make that connection in the first place? They do this using the three-way handshake.

What Is a Three-Way Handshake?

hand shake behind network graphic

In TCP, the device sending the data connects to the device supposed to receive it. The way TCP ports establish reliable connections is called a three-way handshake.

As the name implies, a three-way handshake requires three different interactions, which come in the form of three messages: SYN→SYN-ACK→ACK.

The first is the SYN segment. The sending device sends out a SYN (synchronized sequence number) message to try to communicate with the receiving computer. It is trying to say, "Hello! Are you available to make a connection? "

If the receiving device is available to make a connection, it responds to the device sending the connection request with a SYN-ACK segment. The SYN-ACK segment acknowledges the connection request and sends out a synchronized sequence number in return. In plain terms, the device is saying, "Yes, I acknowledge your request, and I am willing to make a connection."

When this happens, the sending device sends an ACK segment to the receiving device, telling it that it has acknowledged its message. Then a connection is formed, and it begins to transfer data. When the data transmission has been confirmed and completed, the connection is ended.

This way, all data sent to the receiving device is complete and sent in the right order. Moreover, there are no missing packets because a connection was made first.

What Are UDP Ports?

UDP stands for User Datagram Protocol. The User Datagram Protocol is connectionless, which means a host device can transmit data to its recipient without establishing a connection beforehand. UDP ports depend on the UDP/IP protocols. UDP ports include the DNS port (53), the Dynamic Host Configuration Protocol port (68), and the Kerberos port (88), which is used by gaming services.

How Do UDP Ports Work?

Unlike the TCP ports, UDP ports do not need to establish connections before transferring data. So, if you wanted to tell your friend about a new movie imitating the up port, you would have to shout out your conversation and hope that your friend is in the vicinity and can hear you. Pretty unreliable, right?

Data points lighting up and connecting with each other across the globe.

The responsibility of receiving the information you are trying to pass lies solely on your friend. Because you have not made a connection yet, your friend might not hear you properly and only hear bits and pieces or nothing at all.

In UDP ports, the host sends out data in packets (small segments) with no certain destination in mind. Then it hopes that the receiving device gets those packets, which is unreliable as it does not guarantee the data will be received seamlessly. As a result, packets do not get to the receiving end, and data is lost. This is known as packet loss.

What Is the Difference Between TCP and UDP Ports?

Although TCP ports perform the same function of sending information across the internet, they have different features and uses.

Reliability

A TCP port is more reliable for communication and data transfer because, as a connection-oriented protocol, it establishes a connection with the two devices using a three-way handshake before sending data. This way, all the data is received and in the right order. And when there is an error in the process, it is easy to detect. But, this is not the same with UDP ports.

Because of its reliability, TCP ports are used for services where you need secure and complete data transmission like emails, pictures, websites, etc.

Time

video streaming applications

Because UDP ports are connectionless protocols, they save a lot of time by not establishing connections before sending out data packets, which comes in handy for time-sensitive services and where data is received in real-time. UDP ports are used in video, voice, and game streaming.

TCP and UDP Ports, Explained

TCP and UDP ports are networking terms you do not hear regularly, but they are the bedrock of our internet. These two ports play a huge role in your day-to-day life, as without these ports, data transmission would be nigh impossible.