Port numbers used by applications to exchange data packets with TCP and UDP services on the Transport Layer. Most of the Internet Protocols use TCP and UDP services for host-to-host communications.
Who manages the port numbers and protocols that make it possible? Except Dynamic or Private Ports, Internet Assigned Numbers Authority (IANA) assigns all port numbers to the protocols. IANA is a standard organization in the world that is responsible for assigning various standard number resources like port numbers, IP addresses, and autonomous system numbers (ASN) etc.
There are different types of port numbers, used by TCP and UDP protocols.
- Well Known Port Numbers start from 0 to 1023
- Registered Port Numbers start from 1024 to 49151, and
- Dynamic or Private Port Numbers start from 49152 to 65535. The last port number type Dynamic or Private Ports; they cannot be registered with IANA.
The range of port numbers is used for custom or temporary purposes and for automatic allocation of ephemeral ports. When initiating a connection between client and service or Host-to Host, port numbers are usually assigned dynamically to client applications. It is not very common for a client to connect to a service using a Dynamic or Private Port, but sometimes some peer-to-peer file sharing programs do.
The port numbers are also used to establish separate connections between client and servers sides on the internet during using of multiple applications and protocols.
Sometimes few applications or protocols use both TCP and UDP services; it's quite normal. For example, the low overhead of UDP Service with his short header helps DNS to serve many client requests very quickly. But sometimes sending the requested information may require the reliability of the TCP Service. In these situations, some applications may use both Services.
Likewise, sometimes some protocols or applications may also use multiple port numbers for redundancy or backup purposes. And sometimes it uses different port numbers for clients and servers.
Example a- Simple Mail Transfer Protocol (SMTP) uses port number 25 for sending emails. SMTP also uses 587 for email message submission and port 2525 as an alternative port if other ports are blocked or no working.
Example b- DHCP use port 547 for clients and port 546 for clients in IPv6.