Skip to content
AstroPaper
Go back

IP Addressing, NAT, and Geolocation Explained

Edit page

🌐 Public vs Private IP

When you access the internet, you may not have a public IP address directly assigned to your device. Instead, your device gets a private IP, and traffic is routed through a device (your router or your ISP’s equipment) that holds the actual public IP.

Private IP ranges:

RangeUsage
192.168.x.xHome/office LAN
10.x.x.xEnterprise networks
172.16–31.x.xVarious private use
100.64.x.xCGNAT (ISP-assigned)

πŸ”„ NAT β€” Network Address Translation

NAT allows many devices to share a single public IP. When you send a request outbound:

sequenceDiagram
    participant Device as Your Device<br/>(192.168.1.5)
    participant Router as Router<br/>(public IP: 203.0.113.42)
    participant Server as Destination Server

    Device->>Router: Request (src: 192.168.1.5)
    Router->>Server: Request (src: 203.0.113.42) ← translated
    Server->>Router: Response (dst: 203.0.113.42)
    Router->>Device: Response (dst: 192.168.1.5) ← translated back

The router replaces your private IP with its public IP (masquerading), then remembers the mapping to route the response back to you.

Key limitation: You can initiate outbound connections freely, but the outside world cannot reach you directly β€” there is no public IP targeting your device.


πŸͺ† CGNAT β€” Carrier-Grade NAT (Double NAT)

CGNAT adds a second layer of NAT at the ISP level:

Your device        β†’  Your router        β†’  ISP's CGNAT device  β†’  Internet
(192.168.x.x)         (100.64.x.x)          (public IP)

Even your router doesn’t have a public IP β€” the ISP’s equipment does. Outbound access still works identically, but:

CGNAT is common with mobile carriers and some ISPs facing IPv4 address exhaustion.


πŸ‘₯ Users Behind NAT Are Indistinguishable by IP

From the outside world, all users behind the same NAT share one public IP β€” they look identical. This has consequences:

This is why services that need to identify users rely on cookies, accounts, or device fingerprinting rather than IP addresses alone.


πŸ“ IP Geolocation

Even without a public IP on your device, the public IP used by your router or ISP is traceable to a geographic region. Geolocation databases (like MaxMind, ipinfo.io) map IP ranges to locations using:

IP Address Allocation Hierarchy

IANA
 └── RIRs (by region)
      β”œβ”€β”€ APNIC      (Asia-Pacific)
      β”œβ”€β”€ ARIN       (North America)
      β”œβ”€β”€ RIPE NCC   (Europe / Middle East)
      β”œβ”€β”€ LACNIC     (Latin America)
      └── AFRINIC    (Africa)
           └── ISPs β†’ end users

Every IP address is traceable up this chain. RIR databases are public, so anyone can look up the region and ISP for any IP.

Check Your Public IP and Region

curl -s ipinfo.io

Example output:

{
  "ip": "203.0.113.42",
  "city": "Singapore",
  "region": "Singapore",
  "country": "SG",
  "org": "AS12345 Example ISP",
  "timezone": "Asia/Singapore"
}

To get just the IP:

curl -s ipinfo.io/ip
# or
curl ifconfig.me

⚠️ ipinfo.io has a free tier limit of 50,000 requests/month. If you use this in a status bar, cache the result to a file and read from it β€” don’t query live on every refresh.

# Refresh via cron every hour
curl -s ipinfo.io/ip > /tmp/my_public_ip

# Status bar reads from file
cat /tmp/my_public_ip

🚧 Geo-Blocking

Services use IP geolocation to restrict access by country β€” known as geo-blocking or geo-restriction:

ServiceRestriction
NetflixDifferent content libraries per country
BBC iPlayerUK residents only
SpotifySome music licensed per region
Government sitesCitizens of specific countries only

Why services do it:


πŸ›‘οΈ VPN and Bypassing Geo-Restrictions

A VPN (Virtual Private Network) routes your traffic through a server in another country. The destination service sees the VPN server’s IP instead of yours β€” effectively making you appear to be in a different location.

You (SG) β†’ VPN server (UK) β†’ BBC iPlayer
                ↑
    BBC sees a UK IP β€” access granted

VPN Usage in Western Europe & North America

VPN adoption is high in the West, driven by different motivations than in censorship-heavy regions:

MotivationNotes
πŸ”’ PrivacyDistrust of ISPs selling browsing data (US Congress allowed this in 2017)
πŸ“Ί Content accessUnlocking other countries’ Netflix libraries
β˜• Public WiFi securityEncrypting traffic on untrusted networks
πŸ“₯ Torrenting / P2PMasking download activity from ISP
🏒 Corporate VPNAccessing internal company networks remotely

In countries with heavy censorship (China, Iran, Russia), VPN is more of a necessity for basic internet access. In the West, it’s largely a choice for privacy or content.

Major commercial VPN providers (NordVPN, ExpressVPN, Surfshark) advertise heavily in Western markets β€” commonly sponsoring YouTube channels and podcasts.


Edit page
Share this post on:

Previous Post
Static Site Generators β€” A Practical Overview
Next Post
Building TUI Apps with Textual β€” A Practical Guide