Subnetting is borrowing host bits to create more, smaller networks. Learn CIDR notation and slice a network into equal subnets you can compute in your head.
Why: to split one network into several, you extend the prefix — borrowing host bits for the network part — and each borrowed bit doubles the number of subnets while halving their size. When: subnet whenever you need to segment a network (per department, per VLAN, per site). Where: CIDR (Classless Inter-Domain Routing) freed us from the old fixed A/B/C classes, so any prefix length is valid.
Start: 192.168.1.0/24 -> one network, 254 hosts
Borrow 2 bits (/24 -> /26): 2^2 = 4 subnets, each 2^6 - 2 = 62 hosts
192.168.1.0/26 .1 – .62 (network .0, broadcast .63)
192.168.1.64/26 .65 – .126 (network .64, broadcast .127)
192.168.1.128/26 .129 – .190 (network .128, broadcast .191)
192.168.1.192/26 .193 – .254 (network .192, broadcast .255)
Each borrowed bit: subnets x2, hosts-per-subnet /2.Why: the subnets() method carves a network into equal pieces at a target prefix, letting you generate an addressing plan instead of computing it by hand. When: use it to lay out subnets and confirm your manual math. Where: this is exactly the "borrow bits" operation, automated.
import ipaddress
net = ipaddress.ip_network("192.168.1.0/24")
for sub in net.subnets(new_prefix=26): # /24 -> four /26 subnets
hosts = list(sub.hosts())
print(sub, "usable:", hosts[0], "-", hosts[-1])
# 192.168.1.0/26 usable: 192.168.1.1 - 192.168.1.62
# 192.168.1.64/26 usable: 192.168.1.65 - 192.168.1.126
# ...Why: fast subnetting comes down to two lookups — how many subnets a borrow gives (2^borrowed) and how many hosts a prefix holds (2^host_bits − 2) — plus the "block size" that tells you where each subnet starts. When: this is what lets senior engineers subnet in their head. Where: block size = 256 − (mask octet value), and subnets begin at multiples of it.
PREFIX MASK BLOCK HOSTS/SUBNET
/24 255.255.255.0 256 254
/25 255.255.255.128 128 126
/26 255.255.255.192 64 62
/27 255.255.255.224 32 30
/28 255.255.255.240 16 14
/29 255.255.255.248 8 6
/30 255.255.255.252 4 2 (point-to-point links)
Subnets start at multiples of the block size: /26 -> .0 .64 .128 .192