Using a port number we can recognize the exact process to which an Internet or other network message is to be forwarded when it arrives at a server. A host in a network can receive traffic from different hosts at the same time as well as can send traffic to different hosts. So, how the system recognize which data belongs to which application. TCP and UDP solve this problem using port numbers in their header.
Port numbers have the range from 0 to 65535, but port numbers 0 to 1023 has reserved for privileged services and designated as well-known ports number. TCP and UDP on the receiving host know which application to send the data to based on the port numbers received in the headers.
On the source host, each TCP or UDP session assign a random port number above the range of 1024. So that returning traffic from the destination can be identified as belonging to the originating application. A combination of the IP address, Protocol (TCP or UDP) and the Port number forms a socket at both the sending and receiving hosts. in view of the fact that each socket is unique, an application can send and receive data to and from multiple hosts.
The figure above illustrates two hosts communicate with the third host using TCP. Hosts A and host C sending traffic to host B at the same time. Both host A and host C sending traffic destined to Port 80 but from different source ports. Host B can handle both the connections at the same time because of the combination of IP address; Port numbers and Protocols makes each connection different.