How NAT translates public IP addresses to private IP addresses
If you work in the field of IT (Information Technology) then you are most likely familiar with at least the basics of networking such as switches, routers, cabling, IP addresses and so on. But have you ever wondered how the information from the Internet knows how to get to the right computer on your internal network? Or how about at home if you have multiple computers sharing the same Internet connection?
Well it may seem like magic but it’s really not unless of course you consider the whole idea of networking as magic. How this works is by using a process called Network Address Translation or NAT for short. What this does is take the information coming into your network from its external IP address and translating it to the appropriate internal IP address of the computer it needs to go to. If it wasn’t for NAT you would need to have a public IP address for every computer on your internal network and that would not be possible because we are pretty much out of public IPv4 addresses and they are not cheap to begin with if you want your own.
There are 2 main NAT configurations, static (or 1 to 1) or dynamic NAT. There are other more advanced types but we will stick with the 2 most commonly used versions here. Static NAT uses a mapping table to map a public IP address to an internal private IP address so when data comes in for that public IP address the router which stores the NAT table will know which internal private IP address to send the data to. This is used when you have more than one public IP address and want the mapping to stay consistent and not change. You would use a static NAT mapping for something like a web server so the public IP address of the website always points to the internal address of the web server.
Dynamic NAT is used in situations where you only have one public IP address and you need Internet access for multiple inside computers. This is most likely the configuration your home router is using for its Internet connection. This is also called IP masquerading or one to many NAT because one IP address is servicing multiple devices. Dynamic NAT uses Port Address Translation (PAT) where the router assigns the internal client a port number to be used with the IP address so the packets are sent to the right computer. This is needed because multiple internal computers are sharing the same external or public IP address at the same time. If this wasn’t in use then packets would get lost or you would need to have a way to map the public IP address to each private IP address one at a time as needed which would not work too well. This whole process is transparent to the user so there is nothing for them to do in order to make this connection. And the same goes for static NAT after the network administrator completes the configuration on the NAT device.