Making Internet possible with Public IP and Private IP

In this article, you will learn about how the internet works under NAT connection and what is Public IP and How ports are used for packet transfer.

Public IP

A public IP address is an IP address that can be accessed over the Internet.

Example: A postal code of your town is unique over the country. In the same way, your public IP is unique over the internet (World Wide)

You can check your public IP by accessing your router admin panel or by searching ‘MY IP’ on google.


The above picture shows how a public IP is distributed as a private IP by NAT-Network Address Translation by the Switch(wifi router). But notice that when we ask Google for what’s my IP’ the IP is the same for all the devices which is a Public IP address. From this, we can confirm that the server will get our Public IP address whenever we send a request packet and it will send packets back to our public IP.

But how exactly these Individual reply packets are distributed to Devices on private IPs as per their request?  To understand that we have to know the use of port numbers.

Note: Not every computer or home network has a public IP. Ask your ISP whether you have a public IP or private IP (under NAT). Internet Service providers take a PublicIP address and share them to a number of private IPs and distribute each private IP to a particular house/office network.


     NOTE:     192.168.0.X: XXXX — {} — 

                           PrivateIP:Port  —{Our Public IP: port} — destination IP: port


In the above picture, every PC is sending a request packet to a destination IP which is a google server IP (PublicIP: Port number). And at the same time, every device opens a port on its socket to accept the packet on that port when the reply packet is received.

All these packets are first reaching the gateway IP of the network ie., Wifi Router. All packets are managed by Source IP: Port number combination in a Router Table. Once the packet reaches the gateway from there onwards the source IP changes to Public IP of the corresponding network accompanied by a change in port number also. This change in port address is called PAT(Port-Address-Translation). It is used for conflict resolution in cases where the same port is requested by two private IP’s.

See, In the below table and requested the same ports. This is managed by Switch(wifi Router) as shown below.



Now the packets are reached to the server with different data in the packet but the destination IP of each packet is the same( but the port number is different. The server processes the data in each packet and sends the reply back to our network IP with there respective port numbers (Our Public IP: Port).

Now our WiFi router receives the data and distributes them back to the private IPs with their respective port numbers(device Private IP: device port) which are previously stored in the Router.



Share this post

Share on facebook
Share on twitter
Share on linkedin
Share on email
Share on whatsapp