Static NAT vs Dynamic NAT vs PAT ?

TANMAY TYAGI
5 min readMay 10, 2021

--

First let’s understand What’s NAT ?

NAT ( Network Address Translation)-

As name suggests it translates an address to another.

Now, for devices to communicate on the internet, they need a public IP address. But since IPv4 addresses are limited and the devices on the internet are flooding every day, we can’t give public IP to every device on earth. So, to solve this we made a Private IP address concept. We give private IP addresses to devices on the same network.( Imagine your home network, devices connected to your WIFI). Now all devices inside a network have a private IP, which is private so can be repeated in any network. Eg- Your laptop may have a Private IP — 192.168.1.2 and your neighbour’s laptop can too have 192.168.1.2 until they are in different networks(in this case both are on different WIFI).

But when a device goes outside of the network to the public internet, it needs a public IP.

Now the Router translates the private IP of your devices to a public IP. This is NAT.

Consider your home network, all devices connected to a WIFI. Now when you type google.com, the request goes to the router which converts your private IP to public IP and forwards the request to google.com (A 10,000-foot view).

Static NAT

Maps single Private IP address into single Public IP address permanently. (One-to-One mapping)

Let me explain

Say, your PC has an IP(private)- 192.168.1.2. Now when request goes outside the network, router converts it to IP(public)-192.168.2.1( as can be seen in the figure above).

Now assume another PC is there with IP- 192.168.1.3, so router won’t give the 192.168.2.1 to it. You need to create another static entry for it manually.

If you have 1000 devices, you have to create 1000 different static entries as static NAT fix the one to one IP entry permanently.

So this would be a heck of a job and is not feasible in a large network. Eg- a company’s network where there are n number of PCs.

To overcome this there is Dynamic NAT.

Dynamic NAT

Maps Private IP addresses to a pool of Public IP addresses. ( One-to-One mapping but not permanent)

It does not map to public addresses static but uses a group of available public IPs (Public IP pool).

Let’s see an example to understand

Here you have 3 PCs in a network. The router gives them Public IP, from a pool of IPs given to the router manually, usually on first come first serve basis.

1. Lets say, PC0 sends the request first, so the router gave it a public address 192.168.2.1. ( can be seen in the figure)

2. PC1 sent the request after that, router gave it 192.168.2.2.

3. PC2 sent request at last, router gave it 192.168.2.3.

But what if another pc, say PC3, comes into network? And the router only had 3 IPs in the Public IP pool. What then ?

192.168.1.5 is PC3 here

PC3 has to wait until a public IP is free to use. After all, PC3 was last to make the request, so as said before first come, first serve.

Now in this we don’t have to give static One-to-One entries to 1000 PCs. We just have to give a list of Public IPs to the router(Public IP pool) and it intelligently provides the IPs.

Basic Difference btw Static and Dynamic NAT :

In static you can’t use a public IP again once it’s been assigned to a private IP. But in dynamic the public IPs can be reused once they are free. Meaning once a device gets disconnected from internet, the public IP assigned to it can be reused by any other device waiting.

But then, some devices may face issue as their request will not be sent until a public IP is free. How long will they wait to connect to internet?

So to resolve this we have PAT.

PAT ( Port Address Translation)

Maps Private IP addresses to a single Public IP address. ( Many-to-One mapping)

{ Quick fact : Most Home networks use this }

Here PC0, PC1, PC2 all are being mapped to a single public IP 192.168.2.1

This is normally how the address translation is done in our home routers. All your devices have your router’s public IP address when they go out to internet.

Try this - Check your public IP address by using different devices of your home. You’ll find they all have same address, which is your router’s public IP.

Now the problem is how will the router know where to send the packets when the response comes back?

Eg. A device sent a request to google.com. The request goes to google by the public IP of router as all IPs were translated to a single Public IP right ? google sends back a response to the router’s public IP. Now how will the router know to which device it has to give google’s response? All device’s IP got converted into the same public IP.
So for that in PAT, it remembers the port.

Source TCP/UDP port numbers are used to differentiate the different devices and connections. That is why Port Address Translation, make sense?

So, when a device sends a request, the router remembers the port number of the device and when the response comes back it gives the response to the device connected with that port number.

If 2 devices have the same source port number, the translation device(router) change the port numbers for uniqueness.

--

--

No responses yet