NAT, short for Network Address Translation, is what a router does when it rewrites the IP addresses — and usually the port numbers too — of packets as they pass through. Most of the time you'll meet it doing one job: letting every device on your home network share a single public IPv4 address. The router swaps each device's private address for its own public one on the way out, then remembers the mapping so the reply finds its way home.
You use NAT constantly and almost certainly never think about it. But it's also the reason behind a handful of familiar headaches — port forwarding hassles, those "strict NAT" warnings on a game console. So how does it actually work, and why did IPv6 ditch it entirely? That's what this guide covers.
Why NAT exists
An IPv4 address is 32 bits long, good for roughly 4.3 billion unique combinations. Sounds like a lot — until you count up every phone, laptop, TV and sensor online today, which blows past that number many times over. To make the supply stretch, RFC 1918 set aside three blocks of private addresses that anyone can reuse internally, addresses that are never routed on the public internet:
| Range | CIDR | Typical use |
|---|---|---|
10.0.0.0 – 10.255.255.255 | 10.0.0.0/8 | Corporate networks, some ISP routers |
172.16.0.0 – 172.31.255.255 | 172.16.0.0/12 | Corporate networks, Docker defaults |
192.168.0.0 – 192.168.255.255 | 192.168.0.0/16 | Most home routers |
That's how millions of homes can all run 192.168.1.0/24 simultaneously without conflict — none of those addresses ever leave the house. NAT is simply the bridge between that private world and the public internet. Want more on the address side? Our guide to public vs private IP addresses goes deeper.
How NAT works, step by step
Here's the sequence, worked through step by step. Say your laptop sits at 192.168.1.20, it opens a page hosted on a server at 198.51.100.80, and your router's public address is 203.0.113.7.
- The laptop fires off a packet from
192.168.1.20:51000to198.51.100.80:443— port 51000 there is just whatever the laptop happened to pick at random. - The router swaps that source for its own public address plus a port of its own choosing, say
203.0.113.7:40001, and jots the mapping down in its NAT table. - The server sends its reply to
203.0.113.7:40001, blissfully unaware the laptop even exists. - The router checks port 40001 against its table, rewrites the destination back to
192.168.1.20:51000, and hands the packet off to the laptop.
Here's what a simplified NAT table looks like in practice:
| Inside address | Outside (translated) address | Remote host | Protocol |
|---|---|---|---|
192.168.1.20:51000 | 203.0.113.7:40001 | 198.51.100.80:443 | TCP |
192.168.1.31:62210 | 203.0.113.7:40002 | 198.51.100.80:443 | TCP |
192.168.1.45:5353 | 203.0.113.7:40003 | 192.0.2.53:53 | UDP |
None of these entries stick around forever — they expire after a stretch of inactivity. TCP mappings typically get removed the moment the connection closes; UDP, which has no real concept of "closing," just times out after a short idle period instead. That's exactly why a long-lived idle connection can quietly die behind NAT, and why so many apps bother sending keepalive packets at all.
Types of NAT: SNAT, DNAT and PAT
Source NAT (SNAT)
Source NAT rewrites the source address on outgoing packets — the walkthrough above is exactly this. On Linux firewalls there's a variant that just grabs whatever address the outgoing interface happens to have at the time; it's called masquerading.
Destination NAT (DNAT)
Destination NAT does the reverse: it rewrites the destination address on incoming packets. This is exactly how port forwarding works — a rule like "send TCP port 8080 arriving at 203.0.113.7 to 192.168.1.50:80" is nothing more than a DNAT rule. Load balancers lean on the same trick to spread incoming traffic across several servers.
PAT, also called NAPT or NAT overload
Port Address Translation goes a step further and translates ports along with addresses — that's precisely what lets dozens of inside devices share one outside address at the same time, each connection told apart by its own translated port. Nearly every home router runs PAT, and honestly, when someone says "NAT" about their home network, PAT is almost always what they're actually describing.
Static (one-to-one) NAT
Static NAT is simpler still: one inside address, permanently mapped to one outside address. You'll find it in business networks and cloud platforms, where a virtual machine on a private address gets handed its own dedicated public "elastic" or "floating" IP.
Port forwarding and inbound connections
Outbound connections, NAT handles without any help from you. But flip it around: an unsolicited inbound packet shows up at the router with no table entry waiting for it, so the router has no idea which device should get it — and drops it. Want to run a server at home anyway? You'll need a port forwarding rule:
- Give the server a fixed local address — a DHCP reservation in the router is the cleanest way to do it.
- Head to the router's port forwarding page and forward the external port (TCP 25565 for a Minecraft server, say) to the server's local IP and port.
- Don't forget to open the port in the server's own firewall too.
- Then test it from outside your own network with our open port checker. Testing from inside the house will often fail even when everything's set up correctly, simply because plenty of routers don't support NAT loopback (hairpinning).
Some applications skip the manual step entirely and request forwards automatically, using UPnP IGD or NAT-PMP/PCP. Handy for games and voice apps, sure — but it also means any software on your network can open a port, which is why plenty of people just turn UPnP off and add rules by hand instead. Our list of common network ports will tell you what a given port is actually used for.
NAT types and NAT traversal
Peer-to-peer apps — video calls, online games, WebRTC — need two devices that are both behind NAT to talk to each other directly. Whether that actually works comes down to how each NAT behaves. Older terminology from RFC 3489 sorts NATs into full cone, restricted cone, port-restricted cone and symmetric. What really matters is one question: does the NAT reuse the same external port for every destination (easy to get through) or hand out a fresh one each time (symmetric, and a real pain to traverse)? Game consoles just boil all of this down to Open, Moderate or Strict NAT.
So what's the standard toolkit for punching through it?
- STUN — lets a device figure out its own public address and port, as the outside world sees it.
- Hole punching — both peers fire packets at each other simultaneously, which creates matching NAT entries on each side.
- TURN — a relay server that steps in as a fallback whenever a direct connection just isn't possible.
- ICE — tries everything above in turn and settles on whichever path actually works.
Is NAT a firewall?
Here's a common misconception: NAT isn't a security feature. It just has a side effect that looks like one — unsolicited inbound connections have no mapping waiting for them, so they get dropped. A real firewall turns that into an explicit policy, adding rules, logging, and protection against plenty of things NAT simply ignores. Home routers run both together, a stateful firewall sitting alongside NAT. Don't lean on NAT alone to keep you safe — UPnP, manual port forwards, and malware making its own outbound connections all slip right past it.
Why IPv6 does not need NAT
IPv6 addresses run 128 bits long, which changes the math completely. A typical home gets handed an entire /64 prefix or larger — containing more addresses, many times over, than the whole IPv4 internet put together. Every device gets its own globally unique address, so there's simply no shortage left for NAT to fix.
That brings back the internet's original end-to-end model — devices connect to each other directly, no port mapping tricks required, and peer-to-peer apps get a lot simpler as a result. Security instead comes from the router's stateful IPv6 firewall, which blocks unsolicited inbound connections by default, the same job NAT used to do, while still letting you open specific ports to specific devices. There's a related mechanism, NPTv6 (RFC 6296), that can translate one IPv6 prefix into another, though home networks rarely need it. Curious about the bigger picture? See our comparison of IPv4 vs IPv6.
Frequently asked questions
Does NAT slow down my internet?
Not in any way you'd notice. Rewriting headers is a lightweight operation, and home routers handle it in hardware or tightly optimized software. Trouble only crops up if a router's NAT table fills up entirely, something that can happen on cheap hardware juggling huge numbers of simultaneous connections.
What is double NAT?
It means your traffic gets translated twice over — usually because your own router is plugged into an ISP modem that's also doing its own routing. Ordinary browsing is unaffected, but port forwarding now needs rules set on both devices. Switch the ISP device into bridge mode and you remove one of those layers entirely.
Can websites see my private IP address?
Not through a normal connection — NAT swaps it out for your public address before it ever leaves. WebRTC in browsers used to leak local addresses in certain configurations, but modern browsers now mask them behind randomized mDNS hostnames.
How can I tell if I am behind NAT?
Compare the address in your device's network settings against your public IP. See a private-looking address such as 192.168.x.x or 10.x.x.x on the device? NAT is in play.
Commenti
Condividi un consiglio, fai una domanda o racconta come ti è andata con lo strumento.