External IP vs internal IP

Networking

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) IPExternal (public) IP
Uniqueinside one networkon the whole internet
Routed on the internetnever: ISP routers drop ityes
Who assigns ityour router’s DHCP, or youyour ISP (from a block the RIR allocated)
Where it liveseach device’s network interfacethe router’s WAN interface (or the ISP’s CGNAT)
How manyone per deviceusually one per home or office, shared
See it withip -4 addr · ipconfigcurl -s https://ifconfig.me
Costsnothingan 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 withPrefixAddressesDefined inUse
10/816,777,216RFC 1918large LANs, cloud VPCs
172.16 to 172.31/121,048,576RFC 1918Docker’s default bridge network, AWS’s default VPC
192.168/1665,536RFC 1918home and small-office routers
100.64 to 100.127/104,194,304RFC 6598carrier-grade NAT, between ISP and subscriber only
169.254/1665,536RFC 3927link-local: a host that got no DHCP answer picks one itself
127/816,777,216RFC 1122loopback: 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.

NAT: two devices with internal addresses share one external address; the router rewrites source address and port on the way out and reverses it on the way back internal network internet laptop internal addr A phone internal addr B router (NAT) inside LAN gateway addr outside 203.0.113.45 example.com 198.51.100.7 router's translation table internal external remote A:51514 203.0.113.45:40001 198.51.100.7:443 B:51514 203.0.113.45:40002 198.51.100.7:443
Both devices open a connection to example.com from the same source port, 51514. The router gives each its own external port (40001, 40002) on its one public address; the server sees two connections from 203.0.113.45 and replies to those ports (amber), and the router maps each reply back by the table.
NAT: two devices with internal addresses share one external address; the router rewrites source address and port on the way out and reverses it on the way back internal network laptop addr A phone addr B router (NAT) inside: LAN gateway outside 203.0.113.45 example.com 198.51.100.7:443 router's translation table internal external port A:51514 40001 B:51514 40002 both on 203.0.113.45, to :443
Both devices use source port 51514; the router gives each its own external port on 203.0.113.45 and maps the replies (amber) back by the table.

Three consequences follow from that table:

Getting in from outside

Way inHowWorks behind CGNAT
Port forwardinga static table entry: external 203.0.113.45:8080 → the laptop’s internal address, port 8080no: you do not control the ISP’s NAT
UPnP IGD / NAT-PMP / PCPthe device asks the router to add the entry itselfonly PCP, if the ISP supports it
Hole punchingeach 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 entryoften, not with symmetric NATs
Relayboth sides connect out to a public relay that forwards (TURN, RFC 8656)yes, at the cost of a hop
Outbound tunnelthe 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 rangePlays the role ofDefined in
global unicast 2000::/3public addressRFC 4291
unique local fc00::/7 (in practice fd00::/8 + a random 40-bit ID)RFC 1918 privateRFC 4193
link-local fe80::/10169.254.0.0/16, but always presentRFC 4291
::1127.0.0.1RFC 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:

Private is not secure

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.

Sources

Questions? Let's Chat :)

network