I know that a user is assigned a routable IP to access internet so I was wondering if user is also assigned with TCP/UDP port too? I mean just like there is a specific IP of the destination server with whom we are connecting to and there is also a TCP/UDP port on that server on which we are connected. On client side we have external IP of the client. Does that client also have a port number? How to check it?

  • TCP and UDP are separate protocols. Although they use the same port numbers, the TCP and UDP ports with the same number are not the same thing. TCP port 12345 is not the same as UDP port 12345, and both can be used simultaneously for different things.
    – Ron Maupin
    Commented Jul 30, 2016 at 18:01

4 Answers 4


Many ISP's assign you an IP Address for Some Period. Most of the time they have one or more DHCP servers, so that every time you connect your modem or corresponding networking device you get a different IP and if they are not using NAT then most probably you will get a Temporary Public IP Address.

OK, now you have an working IP address and you can start communicating with some Internet Services whether it is a Network Layer Service, Transport Layer Service or Application Layer Service.

For Network layer Service you do not need to open a port on your computer. For example when you are pinging a machine from your computer by using ping command then you are actually using the ICMP protocol and more specifically you are using the ICMP Echo Request and In response you will get an ICMP echo Response. The Network layer can be also used for some other purposes for example IGMP or other Layer 3 protocols. The most interesting fact about this is that you do not need to have any Port open to work with this protocol. You need only an IP address for this.

But in terms of Transport Layer Service whether it is TCP or UDP you need to open a port to communicate with the service. And in terms of Application layer service that port will work with the socket API that will work with the particular Application. Most of the time it will open a higher value port (>1000) that is called an Ephemeral Port aka short lived port because the port will be closed as long as the transport layer is done.

Note that the Ephemeral port number varies from machine to machine.

Now the best Part is that ISP does not restrict you using any port number so you can use any short lived port with you connection.

  • Woah! That's a very detailed answer. Thnx for mentioning its working within layers but I didn't understand the Application layer service. Like I'm using stack exchange app. So it must be application layer service. Does it mean that stack exchange application doesn't require port? What is socket API?
    – defalt
    Commented Jul 30, 2016 at 17:25
  • When a Request a Page from the Stack Exchange App your operating system kernels network module deals with the corresponding transport layer and other layer services. In terms of Transport Layer services the kernel opens a higher number port in that layer and maps somehow the Port and the Process via an API called the Socket API. This API is needed for the mapping of the data between the Process and the Transport Layer.So, if two apps such as Facebook and Stack Exchange are running in your phone the OS multiplexes these network data among them with the ports and with help of socket. Commented Jul 31, 2016 at 8:53

Think of ports as doors. Your PC has a lot of doors and the server also.

A web server has the door 80 open, so if a PC acting as a client wants to connect to the web server, then:

1- The PC opens a random port (door), for example 50000.

2 - From that port the client PC sends a package of data to web server IP address port (door) 80.

3 - If the package is a correct request, then the web server replies from port 80 to client IP address port 50000.

4 - If the reply is correct and the communication ends, the client PC closes its port (door) 50000.

The client starts the communication process to the server, and therefore he chooses a random port in the range known as ephemeral ports (49152-65535) to connect to the server. The port stays open while there is a data transmission with the server. Whenever the transmission ends, the port is closed.

Internet connections require the use of a public IP address. In IPv4 there are 4294967296 (2^32) addresses. Those addresses have been exhausted years ago. So ISPs use NAT (Network Address Translation) to reduce the number of IP Public addresses on each connection.

In a typical home connection to internet, the devices in the home network use addresses in the range 192.168.X.X because that range is considered private and can be used on every home or office network.

The router or modem uses a single public IP address to connect to the external world, so the device has to translate the internal private address to the external one and the ports opened/used inside and outside to avoid confusions.

NAT maps the pair internal address:port to a external address:different port and that mapping let it process the replies correctly, avoiding the confusion if two clients coincidentally open the same source port.

The modem and the NAT process are designed to do this in an automatic way as long as the communication starts from inside the network to external servers.

If you decide to put, for example, a web server inside your home network (therefore, on a private IP address) and you want that the server can be accessed from the external world then you have to manually configure NAT to let it know that incoming connections to port 80 (web server port) must get through the device and go to the internal IP private address of the web server.

  • If ports on client opens and closes itself then why our home wifi router has to do Port Address Translation?
    – defalt
    Commented Jul 27, 2016 at 8:07
  • 1
    I added it to the answer.
    – jcbermu
    Commented Jul 27, 2016 at 8:40
  • 1
    That won't happen. The router keeps a detailed mapping of internal IPs and ports to external IP /ports to avoid that.
    – jcbermu
    Commented Jul 27, 2016 at 9:11
  • 1
    It will be a mess. NAT won't be able to redirect the replies and maybe it will try to forward it to the first available client, if it is no the realreceiver of the reply then it will discard it. The real receiver doesn't get the reply so after a while it will close its port ending communications with the outside world until the user tries again.
    – jcbermu
    Commented Jul 27, 2016 at 9:39
  • 1
    Yes. There is a range called the well-known ports(0-1024) and other one called the registered ports (from 1025 to 49151). Check the list here
    – jcbermu
    Commented Jul 27, 2016 at 13:02

yes.. both sides use port number but don't belong portnumber to users and clients... it's related to apps you work..

TCP/UDP numbers are actually identifiers for finding responsible app (multiplexing using ports)

whenever you open an app and want connection and communication with another side that app in client-side (notice: your client can be server-side for some services! i.g. when you share a folder in your win.. you actually open these ports TCP 139, 445 UDP 137, 138.. waiting for establishing a connection..) randomly assign a number to its port and attach it to your IP (Socket) afterwards that socket talks with server-side which should have well-known port number (telnet 23 , SSH 22 ... )

(The dynamic or private ports are those from 49152 through 65535)

try "netstat -a -n" command and see your current sessions it will help you more to figure out

  • From both the answers I get it why we need ports but I don't understand why our how wifi router does Port Address Translation? Sorry I added this question here but as we have open the discussion about PORTS so I must know about PAT also.
    – defalt
    Commented Jul 27, 2016 at 8:28
  • Port Address Translation (PAT), is an extension to network address translation (NAT) that permits multiple devices on a local area network (LAN) to be mapped to a single public IP address. The goal of PAT is to conserve IP addresses. you need to check out NATconcept.. i.g. you are 5 in your home and all of you want to use internet, it's not logical and possible to reserve 5 public ip address for all of you(the world ran out of IPv4 in 2010) so your ISP gives you a public IP then your router use PAT and multiplex by assigining port to each private IP
    – kasra
    Commented Jul 27, 2016 at 9:08
  • ---- ---- ---- in this case your public IP is and your privates is in so instead of wasting public IP.. your router map that public IP to every private IP you use in your home
    – kasra
    Commented Jul 27, 2016 at 9:13
  • * router can assign same port number to different local inside IP add (your private) but it won't assign same port number to your global inside/outside address (your public address which ISP gives to you)
    – kasra
    Commented Jul 27, 2016 at 9:41

TCP Ports, Connections and Connection Identification

Multiple Connection Management

This identification of connections using both client and server sockets is what provides the flexibility in allowing multiple connections between devices that we take for granted on the Internet. For example, busy application server processes (such as Web servers) must be able to handle connections from more than one client, or the World Wide Web would be pretty much unusable. Since the connection is identified using the client's socket as well as the server's, this is no problem. At the same time that the Web server maintains the connection mentioned just above, it can easily have another connection to say, port 2,199 at IP address This is represented by the connection identifier:

(, In fact, we can have multiple connections from the same client to the same server. Each client process will be assigned a different ephemeral port number, so even if they all try to access the same server process (such as the Web server process at, they will all have a different client socket and represent unique connections. This is what lets you make several simultaneous requests to the same Web site from your computer.

Again, TCP keeps track of each of these connections independently, so each connection is unaware of the others. TCP can handle hundreds or even thousands of simultaneous connections. The only limit is the capacity of the computer running TCP, and the bandwidth of the physical connections to it—the more connections running at once, the more each one has to share limited resources.

  • It would be helpful to provide a reference to your quote.
    – Ron Trunk
    Commented Jul 28, 2016 at 0:05
  • The Header is a hyperlink to the source. Commented Jul 28, 2016 at 0:54
  • So besides having an IP address, a client can also have multiple PORTS open with the same server?
    – defalt
    Commented Jul 28, 2016 at 11:17
  • Yes. I think they are referred to as sockets. The client side port number will be a variable the server side will be port 80 (for example). See List of TCP and UDP port numbers Commented Jul 28, 2016 at 15:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.