# Network Address Translation
## What is NAT
Network Address Translation, commonly abbreviated as NAT, is a method used in networking to translate private IP addresses to a public IP address and vice versa when packets travel between a private network and the public internet. NAT is performed by the router or firewall that sits at the boundary between the private network and the internet. NAT was developed as a solution to the shortage of public IPv4 addresses and has become a fundamental feature of nearly all home and business routers.
## Why NAT is Needed
IPv4 provides approximately 4.3 billion unique addresses, which is insufficient to assign a unique public address to every device on the internet. Private IP address ranges were defined to allow organizations to use any number of private addresses internally without consuming public addresses. However, private addresses are not routable on the internet, so devices with private addresses cannot communicate with the internet without some form of address translation. NAT solves this by allowing many devices with private addresses to share one or more public IP addresses.
## How NAT Works
When a device on the private network sends a packet to the internet, the packet arrives at the NAT router with the device's private IP address as the source. The NAT router replaces the private source IP address with its own public IP address and records the translation in a NAT table along with the source port number. The modified packet is then forwarded to the internet. When a response arrives from the internet server, the NAT router uses the NAT table to look up which internal device should receive the response, replaces the destination public IP address with the corresponding private IP address, and forwards the packet to the correct internal device.
## Types of NAT
Static NAT creates a one-to-one permanent mapping between a specific private IP address and a specific public IP address. This is used when an internal server must be reachable from the internet at a fixed public address. Dynamic NAT maps private addresses to public addresses from a pool of available public addresses. When an internal device initiates a connection, NAT assigns it one of the available public addresses for the duration of the connection. Port Address Translation, also called PAT or NAT overload, is the most common type used in home routers. It maps multiple private IP addresses to a single public IP address by using different port numbers to distinguish between different connections. Many thousands of connections can simultaneously share a single public IP address.
## Advantages of NAT
NAT dramatically reduces the number of public IP addresses needed, extending the useful life of IPv4. It provides a basic level of security by hiding internal IP addresses from the internet. Devices with only private IP addresses cannot receive unsolicited connections from the internet. NAT simplifies network administration because the internal addressing scheme can be changed without requiring changes to the public IP configuration.
## Disadvantages of NAT
NAT breaks the end-to-end principle of IP networking because packets are modified in transit. Some applications and protocols that embed IP addresses within their payload do not work correctly through NAT without special handling. NAT introduces complexity for hosting services that must be accessible from the internet, requiring port forwarding configuration. NAT can create problems for peer-to-peer applications, VoIP, and online gaming. With IPv6 providing enough addresses for every device to have a public address, NAT is expected to become unnecessary as IPv6 adoption increases.Back to Subject