Port 0 has special significance in network programming, particularly in the Unix OS when it comes to socket programming, where the port is used to request system-assigned, dynamic ports. Port 0 is a wildcard port that tells the system to find a suitable port number.
Network Ports Explained
Unlike most port numbers, port 0 is a reserved port in TCP/IP networks, meaning that it should not be used in TCP or UDP messages. Network ports in TCP and UDP range from zero to 65535. Port numbers in the range of zero to 1023 are defined as non-ephemeral ports, system ports, or well-known ports. The Internet Assigned Numbers Authority (IANA) maintains an official list of the intended uses of these port numbers on the Internet, and system port 0 should not be used.
To configure a new network socket connection, it is necessary to assign a single port number to both the source and destination sides. TCP or UDP messages sent by the sender (source) include both port numbers so that the receiver of the message (destination) can send response messages to the appropriate protocol endpoint.
IANA has pre-designated system ports for basic Internet applications such as Web servers (port 80), but many TCP and UDP network applications do not have their own system port and must obtain one from their device's operating system each time they run.