Sub topic 3
CIDR and Prefix Notation
Assume you know binary and decimal conversion, IPv4 addresses, and the basic roles of hosts, packets, and routers. CIDR helps you describe IPv4 networks without relying on fixed address classes.
What CIDR means
Classless Inter-Domain Routing, or CIDR, writes an IPv4 network as:
address/prefix length
The prefix length tells how many of the 32 bits identify the network. The remaining bits identify hosts inside that network.
For example, 192.168.10.0/24 has:
- 24 network bits
- 8 host bits
2^8 = 256total addresses- Usually 254 usable host addresses, because the network and broadcast addresses are reserved
A larger prefix length creates a smaller network. A /28 has 16 addresses, while a /24 has 256.
| Prefix | Host bits | Total addresses | Typical usable hosts |
|---|---|---|---|
| /24 | 8 | 256 | 254 |
| /27 | 5 | 32 | 30 |
| /30 | 2 | 4 | 2 |
The usable-host formula is 2^(32 - prefix length) - 2 for ordinary IPv4 subnets. Point-to-point links and special-purpose networks can use different rules.
Finding a network from an address
To find the network address, keep the prefix bits and set all host bits to zero. To find the broadcast address, set all host bits to one.
Consider 192.168.10.37/27. A /27 mask is 255.255.255.224. The final octet has blocks of 32:
0–3132–6364–95- and so on
Because 37 belongs to 32–63:
- Network address:
192.168.10.32 - First usable address:
192.168.10.33 - Last usable address:
192.168.10.62 - Broadcast address:
192.168.10.63
import ipaddress
net = ipaddress.ip_network("192.168.10.37/27", strict=False)
print("network:", net.network_address)
print("broadcast:", net.broadcast_address)
print("usable hosts:", list(net.hosts()))Subnetting, VLSM, and aggregation
CIDR supports subnetting by borrowing host bits. Splitting a /24 into /26 networks creates four equal subnets, each containing 64 addresses.
Variable-length subnet masks, or VLSM, use different prefix lengths in the same overall address space. A department needing 100 hosts might receive a /25, while a point-to-point link might receive a /30. This avoids wasting addresses.
CIDR also supports route aggregation, also called supernetting. Two adjacent, equally sized networks can be represented by a shorter prefix when their boundary is correctly aligned. For example, 192.168.0.0/24 and 192.168.1.0/24 combine as 192.168.0.0/23.
Exercise
What are the network address, broadcast address, and usable host range for 10.4.7.130/26?
Show answer
A /26 has blocks of 64. The address is in 128–191, so the network is 10.4.7.128, the broadcast is 10.4.7.191, and the usable range is 10.4.7.129–10.4.7.190.