What is a port in computer networking? Explained with examples.

Let us begin by demonstrating the technical concept of a port number with a real-world example. As you may have noticed, a large building contains many apartments. Each apartment is assigned an individual number that only has significance to that building. An apartment’s postal address is globally unique and can be reached anywhere in the world.

A port number in a computer network is similar to an apartment number, while an IP address is similar to a postal address of the building. When a real letter needs to reach an apartment, it must first arrive at the building before reaching the apartment.

What is a port number in networking?

The port number is an integer value of two bytes (sixteen bits) in length. To communicate over a network, an application registers itself with an IP and a port number.

Network packets and ports.

A network packet contains a header and user data. The header contains the source and destination addresses. Each address consists of an IP address and a port number.

For example, an application over the TCP/IP protocol specifies ports in its header. The receiver host looks for the port in the destination address and sends the message to the application listening on that port.

What layer contains information about the port?

In accordance with the OSI model, the transport layer defines the mapping between ports and user applications. For example, the TCP layer establishes the mapping between ports and user applications (e.g., FTP, SCP).

What is the role of ports in network routing?

The port information is irrelevant to the routers during communication between two nodes. The destination node, however, is concerned with the port information in order to identify the correct application to communicate with.

For example, the HTTP server application of www.google.com binds to a well-known port (80) on the server machine and starts listening for client requests. On the other hand, a client uses the service by sending a web request to the server’s IP address and port.

The request also contains the client’s port and IP address in the source address. But here port is generally not a standard port number.

Firewall and ports.

A firewall is an additional layer of security for an organization. It protects the company’s resources from being hacked or misused. The firewall examines each request that enters the company network. If it detects the request is suspicious, it is dropped.

In a network firewall, the port number is also scanned. If the port coming in the destination address is opened on the firewall, the request enters the company premises or else is dropped.

What is the range for port numbers?

Because the value is 16 bits long, it could theoretically range from 0 to 65535. However, this is not the case; certain ports cannot be used because they are in use by standard system applications. The following table summarises the division of ranges according to RFC-6056.

0 to 1023 Well Known ports (e.g., FTP, DNS, etc.)
1024 to 49151Registered Ports (e.g., 36412 for S1AP)
49151 to 65535 Private Ports. You can use these ports without worry.