Mastering IPv4 Subnetting: Theory, Mathematics, and Real-World Application
An IPv4 address consists of exactly 32 binary bits divided into four 8-bit octets separated by decimal periods. Subnetting is the practice of partitioning a single physical or virtual network into smaller, logically organized architectural subnetworks.
In modern IP routing, Classless Inter-Domain Routing (CIDR) uses a prefix length (such as /24) to dictate exactly how many of the 32 bits represent the network portion, leaving the remaining bits to allocate uniquely to individual hosts.
Core Subnetting Formulas
- Total IP Addresses in Subnet:
Total = 2^(32 - Prefix Length) - Usable Host Addresses:
Usable = 2^(32 - Prefix Length) - 2(Subtracting Network ID and Broadcast). - Special Cases (/31 and /32): Under RFC 3021, point-to-point links (
/31) use 2 usable host addresses without broadcast. Single host routes (/32) identify one exact device. - Wildcard Mask Formula:
255.255.255.255 - Subnet Mask = Wildcard Mask.
IPv4 CIDR Reference Cheatsheet (/16 to /32)
| CIDR | Subnet Mask | Total IPs | Usable Hosts | Wildcard Mask |
|---|---|---|---|---|
| /16 | 255.255.0.0 | 65,536 | 65,534 | 0.0.255.255 |
| /20 | 255.255.240.0 | 4,096 | 4,094 | 0.0.15.255 |
| /24 | 255.255.255.0 | 256 | 254 | 0.0.0.255 |
| /25 | 255.255.255.128 | 128 | 126 | 0.0.0.127 |
| /26 | 255.255.255.192 | 64 | 62 | 0.0.0.63 |
| /27 | 255.255.255.224 | 32 | 30 | 0.0.0.31 |
| /28 | 255.255.255.240 | 16 | 14 | 0.0.0.15 |
| /29 | 255.255.255.248 | 8 | 6 | 0.0.0.7 |
| /30 | 255.255.255.252 | 4 | 2 | 0.0.0.3 |
| /31 | 255.255.255.254 | 2 | 2 (RFC 3021) | 0.0.0.1 |
| /32 | 255.255.255.255 | 1 | 1 (Host Route) | 0.0.0.0 |
Frequently Asked Questions
What is the difference between private and public IP addresses?
Private IP addresses are defined under RFC 1918 (10.0.0.0/8, 172.16.0.0/12, and 192.168.0.0/16). They are non-routable on the public internet and intended solely for local LAN and private cloud subnets. Public IPs are globally routable addresses assigned by RIRs (like ARIN, RIPE, APNIC).
How does a Cisco router use wildcard masks?
Wildcard masks invert standard subnet masks. In a wildcard mask, a 0 bit means "match this exact bit", while a 1 bit means "ignore this bit (wildcard)". For example, an ACL targeting subnet 192.168.1.0/24 uses wildcard mask 0.0.0.255 to evaluate only the first three octets.