Anish Ansari
Anish Ansari's Blog


Anish Ansari's Blog


Network Address Translation(NAT)

Anish Ansari's photo
Anish Ansari
·Dec 20, 2020·

4 min read

Play this article

Hello Everyone, Recently, I came across a topic is NAT and, this felt so interesting so I wanted to share what is NAT and, how does it work.

So what we will be discussing in this post is :

  • what is NAT
  • How NAT came in to picture and a little history
  • How NAT works
  • Types of NAT

What is Network Address Translation (NAT)

NAT is used to enable multiple hosts on a private network to connect to the Internet using a single public IP address or we can say that the basic idea of NAT is to allow multiple devices to access the Internet through a single public address.

So basically, NAT helps a private network to communicate with the public network(Internet).

How NAT came in to picture and a little history

Back in 1994, there was a problem with IPV4 and the problem was the IP address was allocated based on the class. Class A address was given to big companies, smaller companies were given class B and smaller get class C address, and so on and, the main problem with this method was that millions of class A address were wasted, many of the class B address were wasted, whereas, number of addresses available in class C is so small that it cannot cater the needs of organizations.

Learn more about IP address classes and Classful Vs Classless Addressing.

The solution to this problem was to create several address ranges that are the private IP address like, learn more about private IP. In this way, we were able to solve problems with classful addressing and this allows us to set up a network and pick one of these addresses to build our network. But again there was a problem that, this doesn’t allow us to communicate on the public internet because on public internet we have to use the public IP address. That’s where NAT came in to picture and helps us to solve this problem by allowing us to communicate with the public let us see how NAT solves this problem.

How NAT works

Network address translation between a private network and the Internet

Network address translation between a private network and the Internet

Network address translation between a private network and the Internet

Image credit: Wikipedia

So if we see in the above picture there is a host connected to a private network, a router most likely be configured to use NAT and, a server connected to the internet. if we want to send a message to the server from an internal device that is connected to a private network with the source address and destination address

Now when we send this message out, the message will easily be transferred to the server because our router looks for the destination address which is

But what happens when the server responds? let’s find out. when the server wants to respond and now destination IP will be and source IP will be, now when the server responds, we know private is address is not routable and the packet gets rejected and thrown away.

Here comes the use of NAT, when the server sent the message to the router which will be configured to use NAT, what it does that it takes source IP ( and store it in a table(also known as NAT table) and replace it with public IP(

Now, if we send any message from private IP to the internet it will reach to the server and when the server responds destination IP will be which is public and points to our router, once the router receives the message it looks in the NAT table and it removes the public IP and replaces it with private address and replaces it with private address and forwards the message back to the device.

Types of NAT

  • Static NAT

A single private IP address is mapped with a public IP address and is generally used for Web hosting.

  • Dynamic NAT

A private IP address is translated into a public IP address from a pool of public IP addresses.

  • Port Address Translation (PAT)

Many private IP addresses can be translated to a single registered IP address. Port numbers are used to distinguish the traffic.

That’s it, I hope it helps you in any way.

Stay home stay safe and happy learning

Buy Me A Coffee

Share this