Skip to content
Related Articles

Related Articles

Difference Between Source Port and Destination Port

View Discussion
Improve Article
Save Article
  • Last Updated : 01 Jun, 2022
View Discussion
Improve Article
Save Article

The packets sent using IP protocol always consist of the source IP address and destination IP address. Then IP protocol passes the incoming data to the transport protocols that require both source port and destination port so that it can reach the intended application process or service. 

The UDP and TCP messages must have a source port and destination port so that it can be known about the source of the application and the intended destination of the application or service. The message coming may belong to a Web Server listening on TCP port 80, or to a DNS Server listening on UDP port 53.

The computer frequently chooses the source port at random as each session has a different random source port associated with it. Routers and firewalls in the network can utilize the source port to differentiate between different communication flows or sessions.

Port numbers, which are 16-bit values, are used to identify application processes (also known as network services). The header of the TCP segment and UDP packet contains the source port number, for the identification of the process that gives the data, and the destination port number for identifying the process that will receive the data.

 Source Port and Destination Port

 

In the above example diagram, Host A is sending a request to the Internet Server by specifying the port 80 that indicates an HTTP request. If the destination port is set to 21 then it becomes an FTP request.

Port numbers are defined in the /etc/ services file on UNIX systems. As the size of the table indicates, there are far more network applications than transport layer protocols. The Assigned Numbers RFC defines port numbers below 256 as reserved for well-known services (such as FTP and telnet). Ports 256 to 1024 are reserved for UNIX-specific services, such as rlogin, which were designed specifically for UNIX systems. Most of them do not belong to UNIX now.

The uniqueness of numbers lies within a given transport protocol; and not between transport layer protocols. Hence, TCP and UDP may and do share port numbers. The protocol and port numbers work together to identify the intended process by which the data should be delivered.

For more details please refer to the article: Various TCP and UDP ports.

Difference between Source Port and Destination Port:

Sr. No. Basis of Comparison Source Port Destination Port
1.  Definition A source port is the TCP or UDP number used by a program to send data to another program on one end A destination port is the TCP or UDP number used by a program on one side of communication to receive data from another program on the other end.
2. Client-Side On the client-side, the source port specifies the program to which the TCP element belongs, and the client gives this port number dynamically. This is basically the process of assigning a port number. On the client-side, the destination port defines the service’s position on the server which permits the server to complete the client’s request.
3. Server Side It identifies the application that is generated the TCP segment. It identifies the application to which the TCP segment is forwarded.
4. Sender and Receiver The sender uses port numbers to inform the receiver which application to use to obtain the data. The receiver uses port numbers to determine which application it should deliver data to.
5. Nature Source ports are basically the user sessions. Destination ports are the server applications.
6. Port numbers It is the next available number for allocation to the user machine. Destination ports may be well-known ports that lie in the range of 0-1023 like port 80 used to specify HTTP Web Services, port 21 used to specify FTP services, port 23 used to specify the Telnet services, etc.

Need of Port numbers:

Ports are an important part of the networking system. Without good port management, your network might not work as intended. Ports are used to exchange data between devices on a network, and in order to confirm that the data is properly shared, you need to properly manage the ports on your devices. A common mistake that beginner networkers make is opening too many ports on their devices. This can lead to security and performance issues, and can also prevent other devices from connecting to your network.

Conclusion: 

The sender uses port numbers to notify the receiver which application to use to receive the data. The receiver uses port numbers to determine which application it should deliver data to.

For more details, read the article The Difference between IP address and Port Number.

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!