←Back to Guides
๐ŸŒNetworking & Infrastructureโฑ๏ธ 16 min read•Updated October 2026

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.

#Networking#IPv4#CIDR#Subnetting#Routing#Linux#DevOps#Cloud

1. Binary Octet Anatomy & The Mechanics of CIDR

An IPv4 address consists of 32 binary bits divided into four 8-bit octets separated by dots (e.g. 192.168.1.1). Classless Inter-Domain Routing (CIDR) represents the subnet mask as a prefix length (/n), indicating how many consecutive leading bits are allocated to the network portion, with the remaining (32 - n) bits reserved for host assignment.
Visualizing CIDR Bitmask Splitting
# 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 PrefixSubnet MaskTotal Addresses (2^(32-n))Usable Hosts (Total - 2, except /31 and /32)Copy
/24255.255.255.0256254 (Standard LAN)
/26255.255.255.1926462
/28255.255.255.2401614 (Container cluster pod)
/30255.255.255.25242 (Legacy point-to-point link)
/31255.255.255.25422 (RFC 3021 point-to-point links; no network or broadcast address)
/32255.255.255.25511 (single host route / loopback)

2. The Host Calculation Formula & Boundary Rules

For any prefix length /n, the total number of IP addresses in the block is exactly 2^(32 - n). However, RFC standards designate two addresses in every traditional subnet as unusable for host endpoints: the first address (all host bits 0) is the Network Identifier, and the last address (all host bits 1) is the Directed Broadcast Address. Therefore, Usable Hosts = 2^(32 - n) - 2.
Calculating Subnet Boundaries for 10.0.4.0/22
# 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.0

Cloud 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 designates three non-routable IPv4 address spaces for private local area networks and Cloud VPCs (AWS, GCP, Azure, DigitalOcean). Traffic from these ranges must pass through Network Address Translation (NAT) or a VPN gateway to communicate across the public Internet.
RFC 1918 BlockAddress RangeSubnet MaskAddress CapacityCopy
10.0.0.0/810.0.0.0 - 10.255.255.255255.0.0.016,777,216 addresses (Enterprise & Cloud VPCs)
172.16.0.0/12172.16.0.0 - 172.31.255.255255.240.0.01,048,576 addresses (Docker default bridge & Kubernetes)
192.168.0.0/16192.168.0.0 - 192.168.255.255255.255.0.065,536 addresses (Home & Small Office LANs)

4. Supernetting & CIDR Route Aggregation

Supernetting combines multiple contiguous smaller subnets into a single larger routing advertisement. This prevents routing table bloat in Core routers and BGP tables. To combine networks, the subnets must be contiguous and aligned to a power-of-two boundary.
Aggregating Four /24 Subnets into One /22
# 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

Inspect network interfaces, calculate masks on the fly, and modify kernel routing tables with iproute2 tools.
Linux iproute2 & Subnet Troubleshooting Commands
# 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 -n

Modern Linux deprecates ifconfig and route in favor of ip addr and ip route.

๐ŸŽ“Explore More Guides

โœจ