NAT (network address translation)
How a home router lets every device share one public IP address: it rewrites each packet on the way out and keeps a table to steer the replies back in.
In 30 seconds
There are not enough IPv4 addresses for every device, so a home or office usually gets one public address. Devices inside use private addresses that only make sense locally.
The router rewrites the source of every outgoing packet to its own address and a port it chooses, and notes the pairing in a table. When a reply arrives on that port, the table says which device it belongs to.
A connection started from outside has no table entry, so it is dropped unless you add a port forwarding rule.
NAT (network address translation), step by step
This is the usual port-translating form of NAT (also called NAPT or PAT). Real tables also record the remote address and protocol, and expire idle rows. IPv6 has enough addresses to do without NAT.
- Step 1: Too few addresses. IPv4 has about 4.3 billion addresses, fewer than the devices that want one. So a home gets a single public address, held by the router. The devices behind it use private addresses such as 192.168.1.10, which are reused in millions of homes and mean nothing on the internet.
- Step 2: A packet leaves the laptop. The laptop opens a connection to a web server. Its packet carries a source address and port (where replies should go) and a destination. The source is private, so a reply addressed to it could never be routed back across the internet.
- Step 3: The router rewrites the source. Before forwarding, the router swaps the source for its own public address and a free port it picks, 40001. It writes the pairing down in its translation table. To the server, the request simply comes from 203.0.113.7.
- Step 4: The reply finds its way back. The server answers to 203.0.113.7 port 40001. The router looks up 40001 in the table, finds the laptop, rewrites the destination back to 192.168.1.10:51000 and passes the packet in. Neither the laptop nor the server notices the swap.
- Step 5: Two devices, one address. The phone connects to the same server and happens to use the same source port, 51000. The router gives it a different public port, 40002. The port number is what tells the two conversations apart, so thousands of connections can share one public address.
- Step 6: Uninvited packets are dropped. An outside host tries to start a connection to the public address on port 8080. Nothing inside asked for it, so the table has no row for 8080 and the router has no idea which device it is for. The packet is discarded. This blocks unrequested traffic as a side effect, though it is not a full firewall.
- Step 7: Port forwarding lets one in. To host a game or web server at home, you add a permanent row by hand: anything arriving on public port 8080 goes to the laptop on port 8080. Now the same uninvited packet has a match and is delivered. This is port forwarding.
Try it yourself
Learn this first
Spotted a mistake on this page?