IP Addresses & Routing

NAT Explained: How Many Devices Share One Address

Understand how your router lets a whole household share one public IP address, what the translation table does and where NAT causes trouble.

Key takeaways

  • Devices inside use private addresses that aren't routed on the public internet; the router presents one public address.
  • The router tells connections apart by port numbers as well as addresses, and keeps a table of mappings.
  • Outbound connections work automatically, while unsolicited inbound ones have nowhere to go without a rule.
  • NAT hides internal addresses but is not a substitute for a firewall.
  • IPv6 provides enough addresses that this kind of sharing is generally unnecessary.

Network Address Translation, or NAT, lets many devices on your home or office network share a single public IP address. Your router rewrites the addresses on packets as they leave, remembers what it changed, and reverses the change on the replies so they reach the right device.

It happens constantly and usually invisibly. You notice it when you try to reach something at home from outside, when a game complains about your connection type, or when two routers end up stacked on one another.

Why it exists

IPv4 addresses are 32 bits long, which allows about 4.3 billion of them, and many are reserved. That isn't enough for every phone, laptop and light bulb. See the IPv4 shortage for the background.

RFC 1918 sets aside three ranges for private use:

Range CIDR form Common in
10.0.0.0 to 10.255.255.255 10.0.0.0/8 Businesses, some providers' equipment
172.16.0.0 to 172.31.255.255 172.16.0.0/12 Businesses, virtual machine setups
192.168.0.0 to 192.168.255.255 192.168.0.0/16 Home routers

Anyone may use these, so millions of networks contain a 192.168.1.10. Because they aren't unique, they can't be routed across the internet. Something at the edge has to translate. The difference is covered further in public vs. private IP addresses.

What happens to one connection

Say your laptop, at 192.168.1.20, opens a web page from a server at 203.0.113.50. Your router's public address is 198.51.100.7. The laptop picks a temporary source port, for example 51500, and sends to port 443.

A web request through NAT (example addresses)
Laptop Home router Web server From 192.168.1.20:51500 1 Addressed to 203.0.113.50 port 443 From 198.51.100.7:40001 2 Router rewrites the source and records the pair Reply to 198.51.100.7:40001 3 The server only ever sees the public address Delivered to 192.168.1.20:51500 4 The table says who this belongs to Laptop Home router Web server From 192.168.1.2 0:51500 1 Addressed to 203.0.113.50 port 443 From 198.51.100. 7:40001 2 Router rewrites the source and records the pair Reply to 198.51.100. 7:40001 3 The server only ever sees the public address Delivered to 192.168.1.2 0:51500 4 The table says who this belongs to

The router also recalculates checksums, since the headers changed. Neither the laptop nor the server needs to know.

The translation table

Each active conversation has an entry linking the inside address and port to the outside address and port, along with the protocol. Because this form of NAT changes port numbers too, it is often called port address translation or NAPT. It is what nearly every home router does.

If two laptops happen to pick the same source port, the router assigns them different outside ports and keeps them separate. Ports give a single public address tens of thousands of distinct slots, and many more in practice, since entries can also be told apart by destination.

Entries don't last forever. TCP entries are removed after the connection closes or after a long idle period. UDP has no closing handshake, so the router relies on a timer, often quite short. Applications that need to stay reachable, such as phone and chat apps, send small keepalive messages to stop their entry expiring.

Inexpensive routers have limited table space. A device opening thousands of connections can fill it and make everyone else's browsing stall.

Variations on the idea

Common forms of address translation
Port translation Many inside devices, one public address Ports distinguish connections The usual home router behavior One-to-one One inside address maps to one public address Often used for a server Saves no addresses Pool based Inside devices borrow from several public addresses A mapping is assigned when needed Found in larger organizations Port forward A fixed rule for incoming traffic One outside port leads to one inside host Configured by you or by software Port translation Many inside devices, one public address Ports distinguish connections The usual home router behavior One-to-one One inside address maps to one public address Often used for a server Saves no addresses Pool based Inside devices borrow from several public addresses A mapping is assigned when needed Found in larger organizations Port forward A fixed rule for incoming traffic One outside port leads to one inside host Configured by you or by software

Why incoming connections fail

When a packet arrives from the internet and matches no table entry, the router has no idea which inside device should get it, so it drops it or handles it itself. That is why a server on your network isn't reachable from outside by default.

You have a few options:

  • Port forwarding creates a standing rule. Our port forwarding guide covers when it is wise.
  • UPnP and similar protocols let software request rules automatically, with trade-offs.
  • Traversal techniques let two devices behind NAT establish a path with help from a server. See NAT traversal.
  • Outbound tunnels or a VPN avoid inbound connections altogether.

A related quirk: from inside your network, connecting to your own public address to reach an inside server works only if the router supports hairpinning, also called NAT loopback. If your server works from mobile data but not from home Wi-Fi, this or split-horizon DNS is the thing to look at.

NAT and security

Because unsolicited traffic has nowhere to go, NAT blocks a lot of random probing as a side effect. That is useful, but it isn't a policy. It does nothing about a device inside that connects out to something malicious, and forwarded ports are fully exposed.

Protection comes from a firewall that tracks connections and decides what is allowed, which most routers include alongside NAT. Firewalls explained describes the difference. This matters especially with IPv6, where devices have globally unique addresses and the firewall alone keeps unsolicited traffic out. Keep it enabled.

Setting up an inbound rule

When you do need to reach an inside device, the steps are similar on most routers, though menu names vary:

  1. Give the device a stable inside address, ideally with a DHCP reservation, so the rule doesn't end up pointing at something else. DHCP explains how reservations work.
  2. In the router's port forwarding or virtual server page, choose the protocol (TCP, UDP or both), the outside port, the inside address and the inside port.
  3. Allow the port in the device's own firewall.
  4. Test from outside your network, such as over mobile data, since testing from inside may fail only because of missing loopback support.
  5. Remove the rule when you no longer need it.

A forwarded port exposes whatever is listening to anyone who tries. Keep that software updated, require strong authentication and never forward a router's or camera's admin page. A VPN into your home is usually the safer route, because you expose one service designed to be exposed.

Timeouts and dropped sessions

A classic NAT symptom: a remote terminal, database connection or smart device works perfectly while busy, then dies after sitting quiet. Neither end closed it. The router (or a firewall along the way) simply discarded the idle entry, and later packets no longer match anything.

The fix belongs at the endpoints. Turn on keepalives with an interval shorter than the idle timeout. SSH has the ServerAliveInterval client setting for this, many database drivers offer TCP keepalive options, and VPN clients often have a "persistent keepalive" field. Lengthening the router's timers can help where it's offered, at the cost of holding more entries.

The reverse problem also occurs. After your public address changes, or the router reboots, the table is gone. Applications that don't notice keep sending into a dead session until their own timeout fires. Software that reconnects cleanly copes best.

Where NAT gets awkward

  • Protocols that put addresses inside the data, such as some older voice and file transfer protocols, break unless the router rewrites the contents too. Router "helpers" that try this sometimes make things worse.
  • Double NAT happens when your own router sits behind another one, often a provider's gateway. Browsing works, but inbound rules need setting twice. Bridge mode usually fixes it.
  • Provider-level NAT adds a layer you can't configure at all.
  • Overlapping private ranges cause trouble when a VPN connects two networks that both use 192.168.1.0/24.
  • Logs and reputation: outsiders see one address for many people, so a block or rate limit applied to it affects everyone behind it.

Checking your own setup

Find your device's address:

Windows:  ipconfig
Linux:    ip address
macOS:    ifconfig

Then sign in to your router and find the address listed on its internet or WAN side. Finally, compare that with the address a public "what is my IP" page reports.

  • If the router's WAN address matches what websites see, your router performs the only translation.
  • If the WAN address is private, there is another NAT device in front of it.
  • If it falls within 100.64.0.0/10, your provider is likely translating as well.

The CIDR calculator helps if you're unsure whether an address falls inside a range.

NAT beyond the home router

The same technique turns up in places you may not think of as routers. A phone sharing its connection as a hotspot translates for the devices attached to it. Virtual machine software often places guests on a private network and translates their traffic through the host, which explains why you can browse from inside a virtual machine but can't connect to it from another computer until you add a forwarding rule or switch to bridged networking.

Container tools do likewise. Publishing a container's port is, underneath, a translation rule from a port on the host to a port inside. Cloud platforms offer managed NAT gateways so that servers with only private addresses can fetch updates without being reachable from outside.

In each case the questions are identical. Which address does the outside see? What creates a mapping? What happens to a connection that nothing inside asked for? Answer those three and most puzzles about "why can't I reach it" solve themselves.

When several layers stack up, such as a container inside a virtual machine behind a home router behind a provider's translator, work from the inside out. Confirm the service answers locally, then from the host, then from another machine on the network, and only then from outside. The first step that fails tells you which layer needs a rule.

Will IPv6 end it?

IPv6 offers so many addresses that every device can have its own globally unique one, restoring direct addressing. A firewall still decides who may connect. There is a prefix translation method for special cases (RFC 6296), but ordinary home IPv6 doesn't use port sharing.

Since much of the internet still runs on IPv4, most networks carry both for now, and your router keeps translating for the IPv4 side. Learning how to check for working IPv6 tells you which of your connections already skip the translation step.

Written for 4Internet with AI writing tools and not reviewed line by line by a person. Check anything you rely on with the maker, provider or standard concerned. Report an error.

Keep reading

All 45 articles in IP Addresses & Routing →

Latest news on this topic