Skip to content
We areTOP 1%

What is NAT, and why is it used?

MediumConceptARP, DHCP & NAT
Track your progress
First attempt
Re-solve after a few days
Final pass before interviews

Answer

NAT (Network Address Translation) is performed by a router that rewrites IP addresses, and usually port numbers, in packets passing between a private network and the internet. It lets many devices with private addresses share one public IPv4 address, which has greatly slowed the exhaustion of IPv4 addresses.

  • The common form is PAT (Port Address Translation, or NAT overload): each internal IP and port pair is mapped to a unique port on the public address and recorded in a translation table, so replies can be returned to the right device.
  • Unsolicited inbound connections have no table entry and are dropped, which hides internal hosts. Running a server behind NAT needs port forwarding, a fixed rule that sends one public port to an internal host.
  • NAT breaks true end-to-end addressing, which complicates peer-to-peer applications such as video calls; they work around it with techniques such as STUN and TURN.

Example: Two home devices reach the same website through a router whose public address is 203.0.113.5:

Inside (private)        Outside (public)       Destination
192.168.1.7:50001  ->   203.0.113.5:40001  ->  198.51.100.20:443
192.168.1.8:50001  ->   203.0.113.5:40002  ->  198.51.100.20:443

A reply arriving at port 40002 is forwarded to 192.168.1.8:50001.

More in ARP, DHCP & NAT

Sign in to track your progress

Your checkboxes, streak and activity heatmap are saved to your account and sync across devices. It is free.
Sign in with email

New here? Create an account