Network Address Translation Explained With Simple Example

Network Address Translation or NAT is a method to map multiple local private IP address to one or more public IP addresses. To achieve this generally a network device for eg: Router which is sitting in the private network, changes the source IP and port field of the IP header in a packet.

Since IP Addresses are limited (IPv4) and as internet devices are too large in number. Hence, NAT is used to apply one or more public IP addresses to a pool of devices present in a private network to save IP addresses.
Theoretically using NAT one public IP Address is sufficient for an ISP hosting a large number of subscribers.

How NAT Works ?

  • Generally, the Network device (Router) who is doing NAT processing, changes the Source IP Address and Source port number in each packet’s IP Header.
  • Since, there are multiple devices present in the private network, hence Router maintains a mapping table which contains private IP address to public IP address conversion details. This table is known as NAT translation table.
  • Using this table Router forwards packets received from Server to correct client machine by converting ip address to client IP address using NAT translation table.
  • NAT is mainly used for IPv4 addresses. Since IPv6 address is of 128 bits, hence NAT is not needed for IPv6 as enough IPv6 addresses are available.

Let’s investigate following image to understand basic working of NAT.

NAT overview
NAT Overview

As shown in above image, Router is performing NAT functionality and converting IP Header field of the packets.

Types of NAT

Based on how NAT functionality is handled, we can divide NAT into following three categories.

Static NAT

In Static NAT case there is one to one mapping between private IP address to public IP address. This type of NAT is mainly used in cases where a device in private network needs to be reachable from Internet. For eg: In case of web hosting services this type of NAT can be used.

Static NAT
Static NAT

Dynamic NAT

In Dynamic NAT case, there is one to one mapping between private IP address and public IP address in which public IP address can be changed time to time. In this case, router is provided with a list of public IP address, and it assigns those public IP addresses to devices in private network. Router assigns public IP address to any device from private network in first come first serve basis. Thus devices can’t have permanent IP address in this case.

Dynamic NAT
Dynamic NAT

Port Address Translation

In this case, many private IP addresses are mapped to single public IP address. Since port numbers can be same between two or more private network devices, hence NAT changes the source port also in IP header of the packet. To forward incoming packets from server to private devices, NAT uses a translation table which has all the mapping information.

Port Address Translation.
Port Address Translation

Advantages

  • It ensures devices can still use IPv4 addresses even though all IPv4 addresses are exhausted.
  • It encapsulates the source and destination IP addresses and, hence providing security.

Disadvantages

  • NAT consumes lot of CPU as it needs to apply on each packet.
  • NAT resolution takes some time and hence adds some extra latency in the connection. This might create issues in latency specific application behavior.

Leave a Reply

Your email address will not be published. Required fields are marked *