Course contents

Unit 8: Core Network ServicesLesson 8.3 (3 of 4 in this unit)75 of 104 in the Network Fundamentals course

Why NAT exists

Private addresses can't travel on the internet. NAT swaps them for public ones at the edge.

Beginner · 6 min read

Covers Private vs. public, IPv4 shortage and Edge router.

Technical definition

NAT (Network Address Translation) is a router function that rewrites IP addresses in packets crossing the network edge, typically replacing private (RFC 1918) source addresses with a public address and reversing the change for replies by using a translation table.

A small office with one public address

A small office has twenty computers, a printer and a web server. The ISP (Internet Service Provider, the company that sells the internet link) gives the office just one public address: 203.0.113.2. Yet every computer can browse the web at the same time. How?

Private and public addresses

A public address is unique on the whole internet. Only one device in the world uses it, so routers everywhere know where to send it. A private address is free for anyone to use inside their own network. RFC 1918 (the standard that set them aside) reserves three ranges:

Private rangePrefixTypical use
10.0.0.0 – 10.255.255.255/8Large companies
172.16.0.0 – 172.31.255.255/12Medium networks
192.168.0.0 – 192.168.255.255/16Homes and small offices

Thousands of homes use 192.168.10.11 at this moment. So internet routers carry no routes to private addresses. If a packet left the office with a private source address, the reply would have no way to find its way back.

Why NAT was needed

IPv4 has about 4.3 billion addresses. That sounded like plenty in the 1980s, but today there are far more phones, laptops and smart devices than that. Most of the regional registries that hand out addresses ran out of free IPv4 blocks years ago. The long-term fix is IPv6. The short-term fix, still used almost everywhere, is to give each site a few public addresses and use private addresses inside.

NAT (Network Address Translation) makes that work. A router at the edge of the network, the point where the office meets the ISP, rewrites the address in each packet:

  • Going out: it swaps the private source address for a public one.
  • Coming back: it swaps the public destination address back to the private one.

To do the second step, the router has to remember each swap. It keeps them in a translation table.

Diagram
R1 swaps PC1's private address at the edge
R1 swaps PC1's private address at the edge
Gi0/0 · insideGi0/1 · outsidePC1IP 192.168.10.11PC2IP 192.168.10.12Web1IP 192.168.10.50SW1NATR1 (NAT)edge routerISPIP 203.0.113.1InternetServerIP 198.51.100.10

Device key: PC1 (computer) · PC2 (laptop) · Web1 (server) · SW1 (switch) · R1 (NAT), ISP (router)

Lines show the example’s network connections. Thick links: uplinks/WAN, as labelled. The coloured path and envelope follow the current step; its text identifies the sender, receiver and traffic type.

Reading the addresses

IP labels identify interfaces or destinations. Subnet labels identify networks; /n is the prefix length. A router ID (RID) identifies a routing process and need not be a reachable interface.

An IP address alone is not a URL. A web URL includes a scheme such as https://; an address on a router or printer does not imply a website.

  • PC1: IP 192.168.10.11
  • PC2: IP 192.168.10.12
  • Web1: IP 192.168.10.50
  • R1 (NAT): edge router
  • ISP: IP 203.0.113.1
  • Server: IP 198.51.100.10
  1. 1. Inside, nothing changes. PC1 sends to 198.51.100.10 from its private address. The switch and R1's inside port see it as normal.
  2. 2. R1 translates and remembers. It changes the source to 203.0.113.2 and adds a row to its translation table: 192.168.10.11 ↔ 203.0.113.2.
  3. 3. The internet only sees the public address. The ISP can route it, and the server replies to 203.0.113.2.
  4. 4. R1 swaps it back. It looks up the table, changes the destination to 192.168.10.11 and sends the reply inside.

What the office gains

  • It saves addresses. One public address can serve hundreds of devices (the “PAT (NAT overload)” lesson shows how).
  • Inside addresses can stay the same. If the office changes ISP, only R1's public side changes. No PC needs a new address.
  • Only the edge router does the work. PCs don't know NAT is happening. The server on the internet doesn't either.

An office front desk works the same way for post. Every letter going out shows the office address, not the person's desk number. The front desk keeps a list of who sent what, so replies still reach the right desk.

NAT has costs too. The router must track every conversation, and devices on the internet can't start a connection to an inside device unless you set that up (the “Static NAT” lesson).

Seeing the translation on R1

At home, open What Is My IP on two devices on the same Wi-Fi. Both show the same public address, even though each has its own private address. That shared address is NAT at work.

On a Cisco router, the translation table shows each swap. This output is based on Cisco documentation, not run on a lab device.

Example output · based on Cisco documentation; exact format varies by platform and software version
R1#show ip nat translations
Pro Inside global         Inside local          Outside local         Outside global
icmp 203.0.113.2:3        192.168.10.11:3       198.51.100.10:3       198.51.100.10:3
Total number of translations: 1
PC1 (192.168.10.11, "inside local") is seen on the internet as 203.0.113.2 ("inside global"). The next lesson explains all four column names.

Test yourself: why NAT exists

Predict · scenario 1

Why can't a packet with source 192.168.10.11 be sent across the internet as it is?

Predict · scenario 2

Where does NAT usually happen?

Predict · scenario 3

What does the router use to send a reply back to the right inside device?