What is TCP Port?

What is TCP?

The Transmission Control Protocol (TCP) is a global communication standard that devices use to send data reliably. TCP is connection-oriented, which means that both the client and the server must be established before data can be sent. This means that the data is trustworthy, ordered, and error-checked while in transit. It is one of the most important protocols in the Internet protocol suite, and the entire set is often referred to as TCP/IP.

Define TCP Port?

TCP ports are unique numbers assigned to various applications. For example, we have opened email and games applications on our computer; we want to send emails to the host using the email application, and we want to play online games using the games application. Different unique numbers are assigned to these applications for them to perform all these tasks. A port number is assigned to each protocol and address. The TCP (Transmission Control Protocol) and UDP (User Datagram Protocol) protocols primarily use port numbers.

A port number is a unique identifier used in conjunction with an IP address. A port is a 16-bit unsigned integer, and there are 65,535 ports available in the TCP/IP model. The port number range is 0 to 65535. The zero-port number is reserved in TCP and cannot be used, whereas the zero-port is not available in UDP. IANA (Internet Assigned Numbers Authority) is the standard body in charge of allocating port numbers.

How do the TCP port works?

The TCP/IP protocol stack relies heavily on the Transmission Control Protocol. TCP is a connection-oriented protocol that requires a connection or circuit between the sending and receiving computers. TCP is one of the two primary methods of data transmission in a TCP/IP network. The other is UDP, which is a best-effort connectionless protocol.

TCP ports are used by devices to communicate via TCP. A TCP port, in general, represents an application or service-specific endpoint identifier. This accomplishes through the three-way handshake.

Consider opening a web browser. When you type “forumautomation.com” your browser automatically converts it to “https://forumautomation.com/.” And with that, you specify the hypertext transfer protocol — and hopefully, you’ll get the page without any problems. This occurs because forum automation’s web server, also known as its HTTP server, is listening for incoming connections on a specific port address.

Sockets and TCP Connections: How Do They Work?

A socket enables communication with another system that is already running TCP server software. A socket is identified by an IP address and a port number. That is, by using different port numbers, a single host can host multiple instances of the same service.

For example, we can configure a web server with “Site 1” listening on the default port of 80, as well as another web server. That is another website on the same server, “Site 2,” with the same IP address but listening on Port 8080.

Why are port numbers required?

A single client can have multiple connections to the same or different servers. Multiple applications may be running on the client at the same time. When the client attempts to access a service, the IP address is insufficient to gain access to the service. The port number is required to access the service from a server. As a result, by assigning a port number to the applications, the transport layer plays an important role in providing multiple communication channels between these applications.

Port number classification

The port numbers are classified into three types:

  • Well-known ports
  • Registered ports
  • Dynamic ports
Port Numbers Range Part Group
0 to 123 Well Known (Contact) Ports
1024 to 49151 Registered Ports
49152 to 65535 Private and/or Dynamic Ports

Well-known Ports

The well-known port numbers are usually between 0 and 1023. Common protocols such as HTTP (hypertext transfer protocol), IMAP (Internet Message Access Protocol), SMTP (Simple Mail Transfer Protocol), and others use well-known ports. For example, we use the http protocol to visit websites on the internet. The http protocol has a port number of 80, which means that when we use the http protocol with an application, the application gets port number 80. It is specified that whenever the http protocol is used, port 80 will be used. Similarly, well-known ports are defined for other protocols such as SMTP and IMAP. The remaining port numbers are assigned to applications at random.

Registered Ports

The registered port numbers are usually between 1024 and 49151. The user processes use the registered ports. These are individual applications as opposed to common applications with a well-known port.

Dynamic Ports

The dynamic port numbers are usually between 49152 to 65535. Ephemeral ports are another name for dynamic ports. When a client connects, these port numbers are dynamically assigned to the client application. The dynamic port is identified when the client initiates the connection, whereas the well-known port is known prior to the connection. When connecting to the service, this port is not disclosed to the client.

How many TCP ports are there?

Because a TCP port is a 16-bit unsigned value, there are only so many TCP ports in the world. There are a total of 65,535 TCP ports available.

You’ve probably heard that due to addressing depletion, the world is transitioning from IPv4 to IPv6. It is also entirely possible that we’ll need to expand the port range to accommodate additional services.

However, the first 1,024 TCP ports are referred to as well-known port numbers, and they are agreed upon by technology vendors. So, if you and I were to start a company and sell nice FTP client software, we’d both agree to use the standard, well-known FTP port numbers.

Define Three-Way Handshake?

TCP connects the device sending the data to the device that is supposed to receive it. A three-way handshake is a process by which TCP ports establish reliable connections.

A three-way handshake, as the name implies, necessitates three distinct interactions, which take the form of three messages: SYN, SYN-ACK, ACK.

The first segment is the SYN segment. To communicate with the receiving computer, the sending device sends an SYN (synchronized sequence number) message. It’s attempting to say, “Hello! Are you available to connect?”

If the receiving device is ready to connect, it sends a SYN-ACK segment back to the device that sent the connection request. The SYN-ACK segment responds to the connection request by sending a synchronised sequence number. In layman’s terms, the device is saying, “Yes, I acknowledge your request, and I am ready to connect.”

When this occurs, the sending device sends an ACK segment to the receiving device to notify it that its message has been acknowledged. Then a connection is established, and data transfer begins. The connection is terminated once the data transmission has been confirmed and completed.

This ensures that all data sent to the receiving device is complete and in the correct order. Furthermore, no packets are missing because a connection was established first.