# NAT (Network Address Translation)

> NAT (Network Address Translation) lets many devices on a private network share a single public IP address by rewriting address information in packets as they cross the router at the network boundary. In its most common form, the router assigns each connection a unique port and keeps a translation table to route responses back to the right device.

Canonical: https://devsunite.com/resources/core-subjects/computer-networks/nat
Last updated: 2026-11-22

Subject: Computer Networks · Category: Network Layer · 4 min read

NAT (Network Address Translation) lets multiple devices on a private network (like a home or office) share one public IP address when communicating with the outside internet, by rewriting the address information in packets as they pass through a router.

## Why NAT exists

Every device connecting to the internet directly needs a unique public IP address, but IPv4's limited address space (roughly 4.3 billion addresses) can't give a unique public address to every device on earth. NAT solves this practically: devices inside a private network get private IP addresses (from reserved ranges like 192.168.x.x or 10.x.x.x) that are only meaningful within that local network, and the router sits at the boundary, translating between those private addresses and the single public address the outside world actually sees.

## How it works, step by step

1. A device on the private network (say, 192.168.1.50) sends a request to an external server.
2. The NAT router intercepts the outgoing packet and rewrites its source address from the private IP (192.168.1.50) to the router's own public IP address, also assigning a unique port number to track this specific connection.
3. The router keeps a translation table mapping that assigned public-facing port back to the original private IP and port.
4. The external server responds to the router's public IP and that specific port.
5. The router looks up the translation table, finds which internal device that port corresponds to, and rewrites the destination address back to the original private IP before forwarding the response inward.

This process (technically called Port Address Translation, the most common form of NAT) is what lets potentially dozens of devices behind one router share a single public IP simultaneously, since each device's connections are tracked by a unique port assignment.

## A worked example

A home network has three devices, 192.168.1.10, 192.168.1.11, and 192.168.1.12, all sharing one public IP, 203.0.113.5. When device .10 requests a webpage, the router rewrites the source to 203.0.113.5, port 40001, and records that mapping. When device .11 makes a request at nearly the same time, the router assigns it a different port, say 40002, from the same public IP. The external servers see two separate connections coming from 203.0.113.5 (with different ports), and the router's translation table ensures each response gets routed back to the correct original device.

## Where this matters in real systems

NAT is running in essentially every home router and most corporate networks today, and it's the single biggest reason IPv4 has remained viable despite its address space being technically exhausted: instead of needing one public address per device, an entire household or office needs just one. NAT also has a real side effect relevant to networking and security: because internal devices aren't directly addressable from the internet without extra configuration (port forwarding), NAT provides a degree of protection against unsolicited inbound connections, even though it wasn't originally designed as a security feature.

## What interviewers actually ask about NAT

- **"What problem does NAT solve?"** It lets many devices on a private network share a single public IP address, dramatically reducing the number of public IPv4 addresses needed.
- **"Walk me through how NAT actually works."** The router rewrites the source address (and assigns a tracking port) on outgoing packets, keeps a translation table, and uses that table to rewrite the destination address correctly on the way back in.
- **"Why is NAT considered a reason IPv4 hasn't been fully replaced by IPv6 yet?"** NAT lets an entire private network operate behind one public address, dramatically stretching the usable life of the limited IPv4 address space.
- **"Does NAT provide security?"** Not by original design, but as a side effect: devices behind NAT aren't directly reachable from the internet without explicit configuration like port forwarding, which does provide some real protection against unsolicited inbound connections.

## Key takeaways

- NAT lets multiple devices on a private network share one public IP address.
- It works by rewriting source/destination addresses (and tracking connections via assigned ports) as packets cross the network boundary.
- NAT is a major reason IPv4 has remained usable despite its address space being technically exhausted.
- As a side effect, NAT provides some protection against unsolicited inbound connections, since internal devices aren't directly reachable without extra configuration.

## Related

- [Previous: IP Protocol Concepts (ARP, RARP, ICMP, IGMP)](https://devsunite.com/resources/core-subjects/computer-networks/ip-protocol-concepts)
- [Next: How the Internet Actually Works](https://devsunite.com/resources/core-subjects/computer-networks/how-the-internet-works)
- [More in Network Layer: IPv4 vs IPv6 Addressing](https://devsunite.com/resources/core-subjects/computer-networks/ipv4-vs-ipv6-addressing)
- [More in Network Layer: Subnetting, Supernetting, and CIDR](https://devsunite.com/resources/core-subjects/computer-networks/subnetting-supernetting-cidr)
- [More in Network Layer: Routing Algorithms (Distance Vector, Link State)](https://devsunite.com/resources/core-subjects/computer-networks/routing-algorithms)
- [More in Network Layer: Routing Protocols (RIP, OSPF, BGP)](https://devsunite.com/resources/core-subjects/computer-networks/routing-protocols)
- [All 101 Computer Networks interview questions](https://devsunite.com/resources/core-subjects/computer-networks)
