This tutorial explains in detail the UDP / TCP connection or session multiplexing with examples. Find out what sockets and port numbers are and how they are used in application mapping.

UDP / TCP connection or session multiplexing

Session connection or multiplexing occurs at the transport layer. It allows multiple applications to send and receive data simultaneously. It assigns a unique number to each session or individual connection to separate it from the others. This unique number is called the port number.

This tutorial is the second part of the article “Similarities and differences between TCP and UDP explained with functions” This tutorial explains the following CCNA topic.

Compare and contrast TCP and UDP protocols

Other parts of this article follow.

Explained segmentation with TCP and UDP Header

This tutorial is the first part of the article. It explains in detail the segmentation process as well as the TCP / UDP header.

TCP features and functions explained with examples

This tutorial is the last part of the article. It explains how TCP provides guaranteed data delivery through its protocol-specific functionality.

In each session or connection, two port numbers are used; source port and destination port. Source port number is used for
identify the session or connection while destination port number is used to identify the application that processes data on the destination host.

To assign the source port number and the destination port number, the transport layer TCP and UDP protocols use two fields in the segment header; source port field and destination port field.

The port number field has a length of 16 bits which allows a total of 65536 (from 0 to 65535) port numbers. Port numbers are divided into three categories; well known, saved and dynamically assigned.

Type of port Range The description
Well known 0 to 1023 The IANA assigns these numbers to applications that are commonly used on the Internet such as DNS and HTTP.
Registered 1024 to 49151 The IANA assigns these numbers to applications that are proprietary applications such as Shockwave and Oracle.
Dynamically assigned 49152 to 65535 The sending device assigns these numbers to sessions.

Known and registered port numbers are used in the destination port field while dynamically assigned port numbers are used in the source port field.

The transport layer on the source host assigns a separate port number to each individual session from the dynamically assigned port numbers. When launching a new session, it selects a currently unused dynamic port number from 49152 to 65535 and assigns it to the session. All segments sent through this session use the assigned port number as the source port number. For the destination port number, the port number of the destination application is used.

The transport layer on the destination host, when receiving segments from the source host, checks the destination port field in each segment to find out which application that segment is to be processed by. After processing, when the destination application returns the data, the transport layer on the destination host uses the same port numbers backwards. It uses the port number of the application through which the segment was processed as the source port number and the port number from which the segment was received as the destination port number.

Let’s take an example. A host wants to access a website. It therefore launches a TCP session. The transport layer assigns a dynamic port number 50000 to this session. Because this session is started to communicate with a web server that uses the HTTP protocol to serve websites, and that the HTTP protocol uses port number 80, it uses destination port number 80.

When receiving segments from this host, the transport layer on the web server checks the destination port number in the segment headers. From the destination port number, it knows that the source wants to communicate with an application that uses the HTTP protocol. While responding to this host, it uses the destination port number 5000 and the source port number 80.

Now assume that the host wants to access another website from the same or from another web server. He therefore launches a new session. Since this is a new session, the transport layer assigns it a new port number. The new port number allows it to keep its segments separate from the existing session.

session multiplexing

If there is only one host accessing remote hosts, the port numbers are sufficient to multiplex the sessions. But if there are multiple hosts, session multiplexing cannot be done just from port numbers.

Let’s take an example. There are two hosts that want to access a web server simultaneously. So they both start sessions. Jointly, they both assign the same port number 50000 to their session. Now, how will the web server know which segment is from which host?

To cope with such a situation, the IP address is used with the port number in the multiplexing. Since the two hosts have different IP addresses, the destination host can easily differentiate their sessions even if they both use the same source and destination port number.

The following figure shows an example. In this example, two hosts and access two web servers and simultaneously with the same source port numbers.

connection multiplexing or application mapping

In this way, to make a connection or session unique or to allow a host to connect to multiple applications simultaneously, three things are used together; Transport layer protocol, source port number and destination IP address. To refer these three things together, a technical term taking is used.

For example, in the figure above; the host uses the socket (, TCP, 50000) to connect with the web server while to connect with the web server, it uses the socket (, TCP, 5001).

Similarly, the host uses the socket (, TCP, 50000) to connect to the web server while to connect to the web server, it uses the socket (20.20 .20.20, TCP, 5001).

The transport layer protocol TCP and UDP both use socket-based multiplexing to provide data to the appropriate application on the source and destination hosts.

That’s it for this part. In the next part of this article, we will understand in detail TCP-specific functions such as windowing and sequencing. If you like this tutorial, don’t forget to share it with your friends via your favorite social site.


Write A Comment