# NAT

> How a whole home or office shares one public IP address on the internet.

- Level: Advanced
- Topics: Networks
- URL: https://tidbit.legios.com.ar/nat/
- In Spanish: [NAT](https://tidbit.legios.com.ar/es/nat/)

**NAT** (network address translation) is what lets many devices share a single public IP address. At home, your phone, laptop and TV each get a **private** address like `192.168.0.12` from the router. Those addresses mean nothing on the internet; they are reused in millions of homes. Your internet provider gives the router just one **public** address, and the router translates between the two worlds.

When your laptop sends a packet to a website, the router rewrites the sender from `192.168.0.12, port 51000` to its own public address and a port it picks, say `200.45.10.7, port 40001`, and writes that pairing in a table. When the answer comes back to port 40001, the router looks it up, rewrites the destination back to your laptop, and passes it in. Each conversation gets its own entry, so the phone and the laptop never get each other's replies.

NAT exists because IPv4 has only about 4.3 billion addresses, far fewer than the devices online, and it stretched them for decades. A side effect is that devices behind NAT cannot be reached from outside unless they started the conversation, which works as a basic shield but complicates video calls, online games and running your own server (hence port forwarding). Providers now often add a second layer, carrier-grade NAT, and IPv6, with enough addresses for every device, removes the need for it. In the cloud, a NAT gateway lets private servers reach the internet without being exposed to it.

## An analogy

An office with one public phone number and a receptionist. Employees call out from their extensions; the receptionist notes who called whom, and when the callback arrives at the main number, transfers it to the right extension.

## Keep in mind

- Private addresses (like 192.168.x.x or 10.x.x.x) are reused everywhere and are not reachable from the internet.
- The router rewrites addresses and ports, and keeps a table to route the answers back.
- Devices behind NAT accept incoming traffic only for conversations they started.
- It exists because IPv4 ran short of addresses; IPv6 makes it unnecessary.

## Go deeper

- [Network address translation on Wikipedia](https://en.wikipedia.org/wiki/Network_address_translation)
- [RFC 1918, the private address ranges](https://www.rfc-editor.org/rfc/rfc1918)

## Related terms

- [IP address](https://tidbit.legios.com.ar/ip-address/): The number that identifies a device on a network, like a postal address.
- [Router](https://tidbit.legios.com.ar/router/): The box that connects your devices to each other and to the internet.
- [Internet](https://tidbit.legios.com.ar/internet/): A worldwide network of networks that lets any connected device reach any other.
- [ISP](https://tidbit.legios.com.ar/isp/): The company you pay to connect your home or phone to the internet.
- [Packet](https://tidbit.legios.com.ar/packet/): The small chunk every piece of internet data is cut into before it travels.
- [Port](https://tidbit.legios.com.ar/port/): The numbered door on a computer that says which program a connection is for.
- [Server](https://tidbit.legios.com.ar/server/): A computer whose job is to answer requests from other computers, all day, every day.
- [IPv6](https://tidbit.legios.com.ar/ipv6/): The newer internet addressing system, with practically unlimited addresses.
