IPv4 Subnetting, CIDR Architecture & Linux Network Routing Runbook
The comprehensive engineering runbook for IPv4 networking: Master binary bitmask mathematics, calculate usable hosts with the 2^(32-n)-2 formula, design RFC 1918 VPC subnets, and debug Linux routing tables.
1. Binary Octet Anatomy & The Mechanics of CIDR
# IPv4 Address: 192.168.1.130/26
# Binary conversion of each octet:
192 = 11000000
168 = 10101000
1 = 00000001
130 = 10000010
# Mask /26 = 26 leading 1s, followed by 6 zeros:
11111111.11111111.11111111.11000000 = 255.255.255.192
# Bitwise AND between IP and Mask yields Network Address:
11000000.10101000.00000001.10000010 (IP: 192.168.1.130)
& 11111111.11111111.11111111.11000000 (Mask /26)
----------------------------------------
11000000.10101000.00000001.10000000 (Network: 192.168.1.128)The bitwise AND operation isolates the network wire address from any host IP.
| CIDR Prefix | Subnet Mask | Total Addresses (2^(32-n)) | Usable Hosts (Total - 2, except /31 and /32) | Copy |
|---|---|---|---|---|
| /24 | 255.255.255.0 | 256 | 254 (Standard LAN) | |
| /26 | 255.255.255.192 | 64 | 62 | |
| /28 | 255.255.255.240 | 16 | 14 (Container cluster pod) | |
| /30 | 255.255.255.252 | 4 | 2 (Legacy point-to-point link) | |
| /31 | 255.255.255.254 | 2 | 2 (RFC 3021 point-to-point links; no network or broadcast address) | |
| /32 | 255.255.255.255 | 1 | 1 (single host route / loopback) |
2. The Host Calculation Formula & Boundary Rules
# Prefix: /22 -> Host bits = 32 - 22 = 10 bits
# Total IPs = 2^10 = 1,024 IPs
# Usable Hosts = 1,024 - 2 = 1,022 hosts
# Subnet Mask = 255.255.252.0 (Block size in 3rd octet = 256 - 252 = 4)
Network Address : 10.0.4.0
First Usable Host : 10.0.4.1
Last Usable Host : 10.0.7.254
Broadcast Address : 10.0.7.255
Next Subnet Wire : 10.0.8.0Cloud VPC Note: AWS and Azure reserve 5 addresses per subnet (3 more than a classic subnet); Google Cloud reserves 4 (2 more). Plan capacity accordingly!
3. RFC 1918 Private Ranges & Cloud VPC Architecture
| RFC 1918 Block | Address Range | Subnet Mask | Address Capacity | Copy |
|---|---|---|---|---|
| 10.0.0.0/8 | 10.0.0.0 - 10.255.255.255 | 255.0.0.0 | 16,777,216 addresses (Enterprise & Cloud VPCs) | |
| 172.16.0.0/12 | 172.16.0.0 - 172.31.255.255 | 255.240.0.0 | 1,048,576 addresses (Docker default bridge & Kubernetes) | |
| 192.168.0.0/16 | 192.168.0.0 - 192.168.255.255 | 255.255.0.0 | 65,536 addresses (Home & Small Office LANs) |
4. Supernetting & CIDR Route Aggregation
# Given four consecutive /24 networks:
# 192.168.0.0/24
# 192.168.1.0/24
# 192.168.2.0/24
# 192.168.3.0/24
# Binary 3rd octets:
# 0 = 000000 00
# 1 = 000000 01
# 2 = 000000 10
# 3 = 000000 11
# Notice the first 6 bits are identical (000000)
# Summarized Supernet Route:
192.168.0.0/22 (Covers 192.168.0.0 through 192.168.3.255)A single /22 route replaces 4 individual routing table entries, accelerating packet forwarding.
5. Linux Network Diagnostics & Subnet CLI Runbook
# Display IP addresses and subnet masks in clean tabular format
ip -br -c addr show
# Display kernel IPv4 routing table
ip route show
# Test which route kernel will use for a specific destination IP
ip route get 8.8.8.8
# Output: 8.8.8.8 via 192.168.1.1 dev eth0 src 192.168.1.50 uid 1000
# Add a static subnet route through a gateway router
sudo ip route add 10.50.0.0/16 via 192.168.1.254 dev eth0
# Inspect listening ports and established TCP sockets without name resolution delays
ss -tulpn -nModern Linux deprecates ifconfig and route in favor of ip addr and ip route.
Related Free Online Tools
Put these techniques into practice immediately with our privacy-first browser utilities:
Calculate network ranges, usable host IPs, subnet masks, wildcard masks, and broadcast addresses from CIDR blocks.
Convert numbers across Decimal, Binary, Hexadecimal, and Octal with bit grouping.
Convert text to 8-bit binary groups, handy practice for reading octets and bitmasks.