Day 6 — CS Fundamentals December — About Networking — Network Address Translation

The last article under CS Fundamentals December was about IP addresses, in general. And it mentioned about one thing that IPv4 addresses are not enough and are being outnumbered by the number of devices on Earth.

So, in this article, I will be writing about Network Address Translation and how it saved IPv4’s a$$.

Let’s dive in!


In my last article, I mentioned about IPv6 addresses being one of the solutions to the problem of not-enough IPv4 addresses but IPv6 addresses have not been adopted to thaaat extent due to another solution and its convenience.

That solution is — Network Address Translation (NAT)

The good thing about this solution is that you still keep on using IPv4 addresses but you just change the way you use it.

This method helps in sneakily sidelining the requirement of each device having a unique IPv4 address so as to use the internet.

So, what I am gonna do is that I’ll explain NAT through an example of your home.

Let’s talk about your home

Your home has many devices. Your computer, your phone, your parents’ phones, etc.

Now natively, you might think that each one of them should have a unique IP address to use the internet but then, we have to deal with the problem of less number of IPv4 addresses as well, right?

So, enter your router (or MODEM, if you call it that :P)

So, you connect to your router at your home right for accessing the internet.

That router is, basically, the middleman in providing you the internet connection and it also performs this thing called Network Address Translation.

So, what it does is, it destroys the need to have unique addresses for each device in the home publicly.

It says, “You know what? All the devices connected to me can have unique IP addresses but those IP addresses need to be unique ONLY INSIDE THAT GROUP OF DEVICES CONNECTED TO ME

So, if a phone and computer are connected to a router, they can have IP addresses same as some other computer in your friends home but they (phone and the computer ) have to have different IP addresses from each other because they are connected to the same router.

This IP address which can be same with some other computer in some other home but has to be unique with the router is called Private IP address.

But how does this work, Yash!

Okay, so the moment, you connect your device to your router, the router sees the current list of devices connected to it and their corresponding IP addresses and then, provides this new device a private IP address which is different from the ones connected to the router.

“Okay, Yash! This is getting complicated. All I hear is ‘IP’, ‘Same’, ‘Different’, ‘Router’. Please teach better!”

Cool cool! Time for an example then :)

For example

When you connect your laptop to your router, the router checks the list of available private IP addresses and gives it to your laptop.

So, in this situation, let’s say your laptop gets the private IP address ->

Now, say, you connect your phone to your router, the router again tries to give a freely available private IP address to it, let it be,

Now, notice this, these IP addresses ( and can be taken up and used by anyone in this world. As I told, they are supposed to be unique “just” amongst the devices connected to that router, that’s it, and hence, they are called “private IP addresses”.

“But then, how will they communicate with some other computer on internet?”

Good Question!

So, the thing is that the private IP addresses are never used to communicate to outside-world computers. Being unique in their own group, devices connected to the same router can talk and communicate to each other using private IP addresses but not with any other computer NOT connected to that router.

So, they communicate by TRANSLATING the private IP address to public IP address when trying to send a NETWORK packet to the outside computer.

Who does that? Router.

So, let’s say, you want to check weather from yahoo weather website (yahoo server).

You send a request for that in the form of network packet, which has details like

Dude! I want to know the weather of Delhi. By the way, I am”.

This network packet is sent to router first. The router translates this sender’s private IP to an available public IP, say, and changes the network packet to this,

Dude! I want to know the weather of Delhi. By the way, I am

and then, passes on the request to the yahoo server.

Now, yahoo server gets this request and responds with,

Okay bro! Delhi’s weather is pretty messed up and it is 40 degrees.

and it sends it back to the assuming that it is the sender.

But leads to the router and the router sees this IP ( and says,

“Aaah! I remember this IP from the routing IP table, I assigned it to the computer with private IP

and then, it changes the network packet to

Okay bro! Delhi’s weather is pretty messed up and it is 40 degrees.

and passes the request to and that computer receives this and hence, knows about Delhi’s messed up weather :P

Router knows which computer corresponds to which IP address (and port number, I’ll explain that) by maintaining a table inside it which it looks up to whenever it receives a request back from the internet.

That table is the NAT IP routing table.

This whole process of translating to and re-translating it back to is called Network Address Translation.

How it saves IPv4’s a$$

This exact thing will happen with every device connected the router with the same public IP.

The next time, another computer/mobile/device, connected to the same router, tries to request any data from the internet, the router will assign the same public IP address for it.

So, see, only one public IP address can be used by multiple devices (all the devices connected to that router) to access the internet.

Hence, reducing the need for unique public IP addresses for each device.

“Okay, final question, Yash! What if simultaneously two computers try to access the internet connected to that router. They both can’t have the same public IP address”

Another good question!

So, the truth is, only and only IP address does not entirely identify a computer. There is a thing called port number which legit identifies from where exactly the request is coming from.

Actually, any complete IP address looks like this ->

Where, is the IP and 8000 is the port number.

“But Yash! I have hardly seen any port number with IP and also in the last example of weather of Delhi, you did not mention anything about the port number :/”

Yes, if port number is not written, then the default port number corresponds according to the respective protocol is assumed.

For example, if the protocol is http and port number is not mentioned, then port number is assumed to be 80 and behind the scenes, the address would be read like

if the protocol is https and port number is not mentioned, then port number is assumed to be 443 and behind the scenes, the address would be read like

So, in the previous Delhi weather example, I did not mention that port number but that meant the port number was default port number i.e. 80 (considering http)

So, getting back to your question, if two computers try to simultaneously access internet through a router, so the router will assign them the same public IP address but on different ports.

So, computer 1 ( to internet, would look like ->

And, computer 2 ( to internet, would look like ->

Router knows which computer corresponds to which port number by maintaining a table inside it which it looks up to whenever it receives a request back from the internet.

That table is the NAT IP routing table.

This process of identifying different computers/applications on the basis of port number is called Port Address Translation (PAT) and it is a type of Network Address Translation technique.

Actually, PAT is most prominently used technique under NAT currently in the world.

Also, one last thing

What did the router say to the doctor when it went to the clinic?

Sorry XD

That’s it!

Phew! That was a pretty intense article!

Anyways, I really hope you understood the article. I’d prefer you to read it again, so as to reinforce the knowledge it is providing because that’s how NAT is, it is difficult to understand the first time but second time, you understand it beautifully.

Anyways, thanks a lot for reaching till here!

Find me on



Email —


Site Reliability Engineer @ Red Hat | ex-Grofers | Contributing to {Cloud, Kubernetes}-native OSS