Whether designing VPC subnets on AWS, debugging container communication in Kubernetes, or exposing a local dev server, a solid grasp of IP routing fundamentals is essential.
1. What Is an IP Address?
An IP (Internet Protocol) address functions like a postal address for connected devices.
- IPv4: Consists of 32 bits arranged into four 8-bit octets (values 0–255), separated by dots (e.g.,
172.217.25.14). With 32 bits, IPv4 yields $2^{32} \approx 4.29\text{ billion}$ distinct addresses—an allocation exhausted by the growth of internet-connected hardware. - IPv6: Uses 128-bit hexadecimal notation (e.g.,
2001:0db8:85a3::8a2e:0370:7334), providing $2^{128} \approx 3.4 \times 10^{38}$ possible addresses, permanently solving exhaustion.
2. Resolving Names: Domain Name System (DNS)
Remembering numeric IP addresses for every service is impossible. DNS acts as a globally distributed key-value lookup directory:
- A user enters
solaqua.devinto a browser. - The operating system's resolver queries recursive DNS servers.
- The resolver returns the associated destination IP (
Arecord for IPv4,AAAArecord for IPv6). - The client initiates a TCP handshake and TLS session directly against the resolved IP.
3. Network ID vs. Host ID and Subnet Masks
An IPv4 address contains two parts:
- Network ID: Identifies the specific network segment (broadcast domain). Devices sharing the same Network ID can communicate directly without passing through an external gateway router.
- Host ID: Identifies the individual device within that network segment.
A Subnet Mask uses bitwise masking to delineate where the network portion ends and the host portion begins:
IP Address: 192.168.1.50 -> 11000000.10101000.00000001.00110010
Subnet Mask: 255.255.255.0 -> 11111111.11111111.11111111.00000000
---------------------------------------------------------------------
Network ID: 192.168.1.0 -> 11000000.10101000.00000001.00000000
Host ID: .50
Every subnet reserves two addresses:
- The Network Address (all host bits 0, e.g.,
192.168.1.0). - The Broadcast Address (all host bits 1, e.g.,
192.168.1.255).
Thus, a 24-bit subnet mask yields $2^8 - 2 = 254$ usable host IPs.
4. Classless Inter-Domain Routing (CIDR)
Historically, IPv4 networks were divided into rigid classes (Class A, B, and C). Modern routing uses CIDR (Classless Inter-Domain Routing), which denotes the subnet mask length with a slash followed by the count of leading 1-bits:
/24$\rightarrow$255.255.255.0(256 addresses, 254 usable)/28$\rightarrow$255.255.255.240(16 addresses, 14 usable)/16$\rightarrow$255.255.0.0(65,536 addresses, 65,534 usable)
AWS VPCs and Google Cloud subnets configure routing rules and peering connections exclusively using CIDR blocks.
5. Private IP Ranges (RFC 1918) & NAT
To prevent IPv4 exhaustion, the Internet Engineering Task Force reserved three address spaces for non-routable private local networks:
10.0.0.0/8(10.0.0.0–10.255.255.255)172.16.0.0/12(172.16.0.0–172.31.255.255)192.168.0.0/16(192.168.0.0–192.168.255.255)
Routers use NAT (Network Address Translation) to map hundreds of internal private IPs through a single public ISP IP address when connecting out to the internet.
6. Exposing Inbound Traffic: Port Forwarding
Because NAT blocks unsolicited inbound connections from outside the private network, hosting a public server on a private machine requires Port Forwarding.
The gateway router inspects destination ports on incoming public traffic and forwards matching packets to the designated internal private IP:
Public Client -> Router (Public IP: 203.0.113.15:8080)
│
▼ (Port Forwarding Rule)
Internal Server (Private IP: 192.168.1.38:8080)
In cloud infrastructure, this role is managed by Layer 4/Layer 7 Load Balancers and Kubernetes Ingress Controllers.