External IP vs internal IP
An internal IP is a seat number; the external IP is the street address. The address your laptop got from the home router means something only inside your own network, and thousands of other networks hand out the same number at the same moment. The internet never sees it: every packet leaves through your router, which swaps it for the one external (public) IP your ISP gave you, 203.0.113.45 in the examples below. The swap is NAT.
| Internal (private) IP | External (public) IP | |
|---|---|---|
| Unique | inside one network | on the whole internet |
| Routed on the internet | never: ISP routers drop it | yes |
| Who assigns it | your router’s DHCP, or you | your ISP (from a block the RIR allocated) |
| Where it lives | each device’s network interface | the router’s WAN interface (or the ISP’s CGNAT) |
| How many | one per device | usually one per home or office, shared |
| See it with | ip -4 addr · ipconfig | curl -s https://ifconfig.me |
| Costs | nothing | an IPv4 address is a scarce asset: AWS bills $0.005 per hour for one |
The private ranges
RFC 1918 (February 1996) set aside three IPv4 blocks that no one owns and no internet router forwards. Anyone may use them; the price is that they mean nothing outside the network that uses them.
| Addresses that start with | Prefix | Addresses | Defined in | Use |
|---|---|---|---|---|
| 10 | /8 | 16,777,216 | RFC 1918 | large LANs, cloud VPCs |
| 172.16 to 172.31 | /12 | 1,048,576 | RFC 1918 | Docker’s default bridge network, AWS’s default VPC |
| 192.168 | /16 | 65,536 | RFC 1918 | home and small-office routers |
| 100.64 to 100.127 | /10 | 4,194,304 | RFC 6598 | carrier-grade NAT, between ISP and subscriber only |
| 169.254 | /16 | 65,536 | RFC 3927 | link-local: a host that got no DHCP answer picks one itself |
| 127 | /8 | 16,777,216 | RFC 1122 | loopback: the machine itself, never leaves it |
Everything else that is not reserved is public. Three more blocks (192.0.2.0/24, 198.51.100.0/24, 203.0.113.0/24, RFC 5737) are public-looking addresses set aside for documentation, which is why this page uses them for every external address.
Why private ranges exist at all: IPv4 has 232 = 4,294,967,296 addresses, fewer than there are phones. IANA handed its last five /8 blocks to the regional registries on 3 February 2011. NAT behind private ranges is what let the internet keep growing on IPv4 after that.
What NAT does to a packet
A home router runs NAPT (network address and port translation, RFC 3022). Every outbound packet gets its source address and source port rewritten; the router records the pair so it can rewrite the reply back.
Three consequences follow from that table:
- The server never learns the internal address. It logs
203.0.113.45, the same for every device in the house. Rate limits, bans and geo-IP all apply to the whole household at once. - One public IP carries about 64,000 simultaneous mappings per protocol (with endpoint-independent mapping, which RFC 4787 requires). The external port is 16 bits; RFC 4787 asks NATs to keep a UDP mapping at least 2 minutes after the last packet, and RFC 5382 an established TCP mapping at least 2 hours 4 minutes.
- Unsolicited inbound traffic has nowhere to go. A packet arriving at
203.0.113.45:8080with no table entry matches no device, so the router drops it. That is why you cannot reach a game server or a camera at home from outside without extra work.
Getting in from outside
| Way in | How | Works behind CGNAT |
|---|---|---|
| Port forwarding | a static table entry: external 203.0.113.45:8080 → the laptop’s internal address, port 8080 | no: you do not control the ISP’s NAT |
| UPnP IGD / NAT-PMP / PCP | the device asks the router to add the entry itself | only PCP, if the ISP supports it |
| Hole punching | each peer learns its own external address and port from a STUN server (RFC 8489), the two swap them over a signalling channel, then both send first so each NAT has an entry | often, not with symmetric NATs |
| Relay | both sides connect out to a public relay that forwards (TURN, RFC 8656) | yes, at the cost of a hop |
| Outbound tunnel | the home machine keeps a connection open to a public server (VPN, reverse SSH tunnel, a tunnel service) | yes |
WebRTC’s ICE (RFC 8445) gathers all three kinds of candidate (direct, STUN-discovered, TURN relay), checks the pairs by priority and keeps the best one that connects: direct beats STUN, TURN is the last resort.
Carrier-grade NAT: two layers of private
Many ISPs, mobile networks almost all of them, no longer give each subscriber a public IPv4 address. Your router’s WAN side gets an address from the RFC 6598 block (100.64 to 100.127), and the ISP’s own NAT (CGNAT) shares one public address among many customers.
Check: open the router’s status page and read its WAN address. If it differs from what curl -s https://ifconfig.me reports, something NATs in front of you. An RFC 6598 WAN address means CGNAT. An RFC 1918 WAN address means either the ISP’s NAT or a second router of your own in front (often the ISP’s modem in router mode): check the modem first, because that double NAT is yours to fix with bridge mode or a port forward on both boxes. traceroute often shows it too: one of the first hops past the router is an RFC 6598 address.
What changes: port forwarding stops working (the outer NAT is not yours), the public address is shared with strangers so one bad neighbour can get it rate-limited or blocked, and the ISP gives each subscriber a limited block of ports on it.
RFC 6598 made that block its own range because ISPs could not use RFC 1918 for it: a subscriber’s LAN may already use any of those, and the same block on both sides of the home router breaks routing.
IPv6: every device gets a public address
IPv6 has 2128 addresses; a single home usually gets a /56 or /64 prefix, 264 addresses per subnet. Each device gets a globally routable address and no NAT is needed: the address the server sees is the device’s own.
| IPv6 range | Plays the role of | Defined in |
|---|---|---|
global unicast 2000::/3 | public address | RFC 4291 |
unique local fc00::/7 (in practice fd00::/8 + a random 40-bit ID) | RFC 1918 private | RFC 4193 |
link-local fe80::/10 | 169.254.0.0/16, but always present | RFC 4291 |
::1 | 127.0.0.1 | RFC 4291 |
Two things NAT did by accident still have to be done on purpose: privacy (RFC 8981 temporary addresses rotate the host part, so a server cannot follow one device across days) and blocking inbound (the router’s stateful firewall drops unsolicited connections, the job NAT’s missing table entry used to do).
In the cloud the OS never sees its public IP
An EC2 instance’s network interface carries only its private VPC address, from the VPC’s RFC 1918 block. Its public IPv4 or Elastic IP is a 1:1 NAT at the VPC’s internet gateway: ip addr on the instance does not show it, and a service that must know it asks the instance metadata service at 169.254.169.254. GCP and Azure work the same way.
Practical rules:
- Traffic between instances goes to private IPs. Same network, no detour through the internet gateway.
- Bind servers to
0.0.0.0or the private IP. Binding to the public address fails: the interface does not have it. - The app behind a load balancer sees the balancer’s internal IP. The client’s real external IP arrives in
X-Forwarded-Foror the standardForwardedheader (RFC 7239). Trust that header only when the request came from your own proxy, otherwise any client can set it.
Private is not secure
- NAT is not a firewall. It drops unsolicited inbound packets because it has no entry for them, not because of a policy. A forwarded port, a UPnP request from malware or an IPv6 address without a firewall exposes the device directly.
- SSRF turns your server into a way in. A web app that fetches user-supplied URLs runs inside the private network;
http://169.254.169.254/or an internal Redis on port 6379 from its side reaches what the internet cannot. Validate the resolved address, not the hostname, block private, link-local and loopback ranges, connect to that same resolved address (no second lookup, or DNS rebinding swaps it), and re-check it on every redirect. - A private address in a log or a page leaks the network layout. It cannot be reached from outside, but it tells an attacker how the network is built.
TL;DR: The internal IP (RFC 1918: starting 10, 172.16 to 172.31, or 192.168) identifies a device inside one network and is never routed on the internet; the external IP is the one public address the internet sees, normally the router’s, shared by every device behind it. NAT rewrites source address and port outbound and reverses it from a table, so outbound works and unsolicited inbound is dropped: port forwarding, hole punching or a relay gets you in. A router WAN address in the RFC 6598 block (100.64 to 100.127) means carrier-grade NAT, a second layer you do not control. IPv6 gives each device a public address and replaces NAT with a firewall; in the cloud the public IP is a 1:1 NAT the instance never sees on its interface.
Related
Sources
- RFC 1918, Address Allocation for Private Internets
- RFC 6598, IANA-Reserved IPv4 Prefix for Shared Address Space
- RFC 5737, IPv4 Address Blocks Reserved for Documentation
- RFC 3927, Dynamic Configuration of IPv4 Link-Local Addresses
- RFC 3022, Traditional IP Network Address Translator
- RFC 4787, NAT Behavioral Requirements for Unicast UDP
- RFC 5382, NAT Behavioral Requirements for TCP
- RFC 8489 (STUN) · RFC 8656 (TURN) · RFC 8445 (ICE)
- RFC 4291, IPv6 Addressing Architecture · RFC 4193, Unique Local IPv6 Unicast Addresses · RFC 8981, Temporary Address Extensions
- RFC 7239, Forwarded HTTP Extension
- Free Pool of IPv4 Address Space Depleted — NRO, 3 February 2011
- Amazon EC2 instance IP addressing — AWS docs
- New AWS public IPv4 address charge — AWS News Blog