What Is NAT? — Translating Private IPs to a Public IP, and Port Forwarding

⏱ approx. 9 min views 36 likes 0 LOG_DATE:2026-06-10
TOC

NAT (Network Address Translation) rewrites the source/destination IP address of packets as they cross a router (the border). The reason your many home devices all have similar 192.168.x.x numbers yet appear as a single public IP from the outside is NAT. In particular PAT (NAPT / IP masquerade), which juggles port numbers to achieve "many : 1", runs on almost every home and office router today. This article covers why NAT exists, its flavors, the translation table, port forwarding, the side effects it causes, and why "NAT is not a firewall."

01

What NAT is — rewriting addresses at the border #

NAT is the translator standing at the boundary between the private world (your LAN) and the public world (the Internet). It swaps the source IP of outbound packets to a public IP, and swaps replies back to the original host.

▸ In plain terms — "the company's main phone number"

Inside there are many extensions (private IPs), but the outside sees one main number (the public IP). When you dial out, the other party sees the main number; incoming calls are routed by the operator (the router) to the right extension. The operator tracks "which extension is talking to whom right now" in a ledger — that is the NAT translation table.

02

Why it was born — IPv4 exhaustion and private addresses #

IPv4 has only about 4.3 billion addresses, and exhaustion was visible early on. So "inside-only numbers" — private addresses (RFC 1918) — were defined, and the NAT approach of translating to a public IP only when talking outside took hold.

RangeCIDRTypical use
10.0.0.0 – 10.255.255.25510.0.0.0/8Large enterprise
172.16.0.0 – 172.31.255.255172.16.0.0/12Mid-size / Docker, etc.
192.168.0.0 – 192.168.255.255192.168.0.0/16Home / small office

These addresses are not routed on the Internet, so talking to the outside always requires NAT (or IPv6).

03

Three flavors — Static / Dynamic / PAT #

TypeMappingUse
Static NAT1 : 1 fixedGive a public server the same public IP every time
Dynamic NATmany : many (pool)Lend out free public IPs from a pool
PAT / NAPTmany : 1 (+ ports)The home/office default. One public IP shared by all hosts

When people say "NAT", they almost always mean PAT — called MASQUERADE on Linux and "IP masquerade" on home routers.

04

How PAT works — ports collapse many into one #

How do you achieve "many : 1"? With port numbers. The router records the mapping of "inside IP:port" to "public IP:rewritten port" in a translation table, then reverse-looks-up returning packets to send them to the right host.

1. Outbound
PC-A 192.168.1.10:51000 -> dst 93.184.216.34:443. The router rewrites the source to public IP:new port 203.0.113.5:40001 and records the mapping.
2. Inbound (reply)
The server replies to 203.0.113.5:40001. The router reverse-looks-up the table and restores the destination to 192.168.1.10:51000 for the LAN.
3. A different host gets a different port
If PC-B talks at the same time, the router assigns a different public port 40002. Because hosts are told apart by port, hundreds can ride on one public IP.
05

Port forwarding — reaching an inside server from outside #

PAT assumes "inside -> outside" traffic. The table is only created by an outbound request, so nobody can come in from outside on their own. To host a game server or website at home, you carve a path manually — that is port forwarding (DNAT / static port mapping).

Router example: public 8080 -> internal web server
# Forward incoming 203.0.113.5:8080 to 192.168.1.50:80 WAN 203.0.113.5 : 8080 ──▶ LAN 192.168.1.50 : 80

# On a Linux router, the same via iptables DNAT $ iptables -t nat -A PREROUTING -p tcp --dport 8080
-j DNAT --to-destination 192.168.1.50:80

▸ A spot that easily becomes an attack surface

Port forwarding means "opening a hole directly to the Internet". Carelessly forwarding an old router admin page, RDP (3389), SMB (445), or an unauthenticated IoT device gets it scanned and breached fast. Automatic hole-punching via UPnP is a classic malware abuse vector too. Expose the minimum, require authentication, and keep it patched.

06

What NAT breaks — the cost of losing end-to-end #

NAT is convenient, but it breaks the Internet's original assumption that "every host can reach every other host." Hence the side effects.

  • You can't initiate from outside — P2P, online matches, and home servers don't connect cleanly.
  • VoIP / video calls — when both sides are behind NAT they can't connect directly, so STUN (learn your own public address) / TURN (relay through a server) / ICE punch holes.
  • CGNAT (Carrier-Grade NAT) — as IPv4 exhaustion deepens, ISPs stack yet another NAT. Users may not even have a public IP and can't open ports.
  • IPv6 is the real fix — with its vast address space, NAT is generally unnecessary and end-to-end returns.
07

Security meaning — "NAT is not a firewall" #

Because PAT has the side effect of "you can't come in from outside," people mistake NAT for a defense. But NAT's purpose is address translation, not filtering.

CapabilityNAT (PAT)Firewall
Block unsolicited outside -> insideMostly blocked as a side effectExplicitly controlled
Control inside -> outside trafficPasses throughControlled by policy
Stop malware's outbound C2Doesn't stop itCan stop it

Malware's C2 traffic (inside -> outside) sails right through NAT. Put a proper stateful firewall at the border and treat NAT purely as the address-translation role.

08

Summary — five things to remember #

  • NAT rewrites IP addresses at the router. It was born because of IPv4 exhaustion.
  • The default is PAT (NAPT / IP masquerade). Port numbers let many hosts share one public IP.
  • Replies return to the right host via a reverse lookup of the translation table.
  • Outside -> inside fails because there's no table entry. To publish, use port forwarding (DNAT) (which adds attack surface).
  • NAT is not a firewall. Inside -> outside passes through; put a real firewall at the border.
𝕏 Post B! Hatena