Table of contents
1.
Introduction
2.
How NAT works
3.
Types of NAT
3.1.
Port Address Translation 
3.2.
Dynamic NAT 
3.3.
Static NAT  
4.
Advantages of NAT
5.
Disadvantages of NAT
6.
Frequently Asked Questions
6.1.
How does NAT work?
6.2.
Does NAT occur before or after routing?
6.3.
Can NAT be deployed in a public wireless LAN environment?
7.
Conclusion
Last Updated: Mar 27, 2024

Network Address Translation(NAT)

Author Ankit Kumar
0 upvote
Career growth poll
Do you think IIT Guwahati certified course can help you in your career?

Introduction

Initially, the Internet wasn't designed to be used by everyone, and as IPv4 provided 232 addresses, this was a vast number. But, As time passed, the Internet grew, and so did the number of devices and the number of addresses. The number of addresses began to run out. The solution that they thought of was that since we don’t have enough addresses to represent every machine, what we can do is we can kind of fake things out. 

So, the brightest mind got onto the work and devised a solution, NAT. NAT stands for Network Address Translation. Private addresses were developed to help prolong the life of IPv4. Three groups of addresses were created, and they were called private addresses. 

These addresses can be used over and over again. So, we're left with a small group of addresses that can be used repeatedly. But there was a constraint too. These addresses were used only inside an internal network and not allowed over the public Internet. Let's try to understand the concept of NAT.

How NAT works

Network address translation allows a single device, such as a NAT firewall, NAT router, or other network address translation device, to serve as an intermediary between the public and private networks—the Internet and any local networks. When a device does something outside of its network, it might be represented by a unique IP address. 

For example, let's say in your home computer there is your printer and your tablets they all are assigned a private address from the 192.168 0/0 group this works fine communicating with each other they get along pretty happily but if these addresses can't access the public Internet does that mean they can't do anything outside of their internal network now let's add a Router into the equation when you sign up with an ISP they will give you a public address. 

This can be used on the Internet, but usually, they only provide you with one, so with all these devices, how can we use just one public address? Now, NAT comes into play. 

NAT converts private addresses to public addresses. NAT is a router function where IP addresses of IP datagrams are replaced at the boundary of a private network. Or in simple words, the information comes at the public IP address and port, and the NAT instructions direct it to the appropriate destination without disclosing the private IP addresses of the destinations.

Let's take a closer look at how this works. We will simplify this to make it easier to understand by looking at this flowchart.

Types of NAT

There are three types of Network Address Translation. 

  1. Port address translation
  2. Dynamic NAT
  3. Static NAT
NAT

Port Address Translation 

PAT stands for Port Address Translation, also known as NAT Overload. This is by far the most popular version of NAT. And this is what is generally used at the home when the computer sends data to the Router. The Router looks at the data and the source address, the port number, the destination address, and the destination port number. Now the port number is significant. Port number will not only distinguish which device the data belongs to but also tell the device which application that data belongs to. 

Very simply, the Router swaps out the private source address and port number. Then swap it for a public address and port number. The port number will often stay the same, but if it's already being used, the next available one will be selected to keep track of which public addresses belong to which private addresses. The Router builds a NAT table. This table matches the private address and port number to the public address and port number. 

Once the Router swaps the addresses and adds them to the table, it rebuilds the data and sends it on its way. When the data comes back, the Router again looks at the addresses. The source address is now where it came from some web service. The destination is now the public address in the port number. The Router looks at this and checks the destination against the NAT table. If it finds a match, the Router will swap out the public address and port number for the private address and port number. It will then send the information on its way. 

Once the computer has the data, the port number will tell which application to send it. For example, if you're searching the Internet, it can even tell which tab to send data to. Next, we'll see the second type of NAT.

Dynamic NAT 

Dynamic NAT doesn't save addresses because it's a  one-to-one mapping of addresses, but it's still a type of NAT nonetheless. The dynamic NAT needs to create a  pool of public addresses manually. This would require us to purchase these public addresses from our ISP. Dynamic NAT works in pretty much the same way when data comes in. 

The Router looks at the source and destination address and swaps out the source address for the first available public address from that pool. Then it sends data on its way. When the data comes back, it again looks at the source and destination addresses. Suppose it finds a match in the NAT table from the destination address. It gets swapped out for the private address and then is sent on its way. After this is done, the public address will return to the pool, ready to be used again. Now, we'll look at the last type of NAT.

Static NAT  

Static NAT requires us to type the entries to the NAT table manually. We have to tell the Router which private address and port number will be translated to which public address and port number. Once this is done, it works just like the other two versions. When the data comes in, it checks the NAT table for the source address, and when it finds a match, it swaps the address for the public address. Then it is sent on its way. 

When the data comes back, the address is checked against the NAT table. The public address is again swapped for a private address and then is again sent on its way to the device. 

This version of NAT is mainly used for public servers like web servers, where the port will always be 80,  for example, for HTTP.

NAT translates private addresses to public addresses. It does this by using a NAT table to record these translations. Very clever but pretty Simple.

Now let’s see the Pros and Cons of NAT.

Advantages of NAT

  1. Cost Saving:- Organizations do not need to acquire IP addresses for every machine on the network when utilizing NAT with private IP addresses. Multiple devices can share the same IP address. As a result, substantial cost savings are possible.
     
  2. Consistent Network:- NAT ensures that network addresses are consistent. The appropriate address space should be assigned when a public IP address is used. When the network grows, more IP addresses will be necessary.
     
  3. Network Security:- In NAT, the source and destination addresses are entirely concealed. The hosts inside the NAT cannot be accessible by hosts on other networks unless the user allows it. As a result, NAT adds an extra layer of network protection.

Disadvantages of NAT

  1. Decreased Performance:- When a visitor sends a request to a distant server, the NAT router ensures that the connection belongs to it. However, some hosts incorporate security features that limit the number of requests received. If the defined number is exceeded, no more requests will be processed. It can lead to performance degradation, particularly in real-time communications like VoIP.
     
  2. Memory Usage:- All incoming and departing data packets must be examined by NAT, which converts local and global IP addresses. This causes all translation information to be retained in memory. As a result, the NAT consumes a large amount of memory and computing power.
     
  3. Troubleshooting:- When using NAT, the end-to-end traceability gradually decreases. The IP addresses here are continually changing over many NAT hops. It makes troubleshooting more difficult, if not impossible, particularly in rural areas.
     

Must Read Subnetting in Computer Networks

Frequently Asked Questions

How does NAT work?

NAT, in essence, allows a single device, such as a router, to function as an agent between the Internet (or public network) and a local network (or private network). Implying that just a single unique IP address is necessary to represent an entire group of machines to anyone outside their network.

Does NAT occur before or after routing?

The sequence in which the transactions are completed using NAT depends on whether a packet moves from the inside network to the outside network or from the outside network to the inside network. Inside to outside translation happens after routing, whereas outside to inside translation occurs before routing. 

Can NAT be deployed in a public wireless LAN environment?

Yes, Static NAT is how to deploy NAT in a public wireless LAN environment.

Let us now summarize our learning in the next section.

Conclusion

In this article, we discussed NAT. The problems by IPv4 and how it was solved by using NAT. We discussed three different types of NAT, namely Port Address Translation, Dynamic NAT, and Static NAT. Then we discussed how it could be beneficial as it saves capital. It also has a consistent network and enhances network security. Also, the disadvantages of NAT lead to decreased performance, increased memory usage, and troubleshooting issues. In the end, we discussed the FAQs of NAT.

Recommended Readings:


Do check out The Interview guide for Product Based Companies as well as some of the Popular Interview Problems from Top companies like Amazon, Adobe, Google, etc. on Coding Ninjas Studio.

To study more about computer networks, refer to disadvantages of computer network.

Check out some of the amazing Guided Paths on topics such as Data Structure and Algorithms, Competitive Programming, Basics of C, Basics of Java, Computer Networks, etc. along with some Contests and Interview Experiences only on Coding Ninjas Studio

Live masterclass