A large network is easier to manage, faster and more secure when divided into smaller subnetworks. Subnetting and CIDR make this division, and use addresses efficiently.
Subnet Masks
A subnet mask marks which bits of an address are the network (and subnet) part: 1s for network bits and 0s for host bits. 255.255.255.0 means the first 24 bits are network bits. The network address of a host is found by a bitwise AND of the address and the mask. Two hosts are on the same network only if their network addresses match; otherwise, traffic goes through a router (the default gateway).
Definition: Subnetting. The division of a single IP network into smaller networks, called subnets, by borrowing bits from the host part of the address to form a subnet part.
CIDR Notation
Classless Inter-Domain Routing (CIDR), introduced in 1993, replaced the rigid classes. It writes an address with a prefix length, the number of network bits: 192.168.10.0/24 means a 24-bit network part, the same as mask 255.255.255.0. A /n network has 2^(32−n) addresses, of which 2^(32−n) − 2 can be used by hosts (the network and broadcast addresses are excluded). CIDR allows networks of any size, reducing waste, and route aggregation (supernetting) combines several networks into one routing entry, such as four /24 networks into one /22, which keeps internet routing tables small.
How to Subnet
To divide a network into S equal subnets, borrow b host bits with 2^b ≥ S. The new prefix is n + b, each subnet has 2^(32−n−b) addresses and 2^(32−n−b) − 2 usable hosts, and the subnets start at multiples of the block size 2^(32−n−b) in the octet where the boundary falls. To size subnets for a given number of hosts H, choose host bits h with 2^h − 2 ≥ H. Variable Length Subnet Masking (VLSM) gives different subnets different sizes, allocating the largest first, which uses addresses even more efficiently.
Useful Prefixes
/24 = 256 addresses (254 hosts), /25 = 128 (126), /26 = 64 (62), /27 = 32 (30), /28 = 16 (14), /29 = 8 (6), /30 = 4 (2, used on point-to-point links between routers).
Table 2.6: Common CIDR prefixes
| Prefix | Mask | Addresses | Usable hosts |
|---|---|---|---|
| /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 |
| /30 | 255.255.255.252 | 4 | 2 |
Example 2.6: Dividing a /24 into four subnets
Problem: Divide 192.168.10.0/24 into four equal subnets for four departments. Give each subnet's network address, usable range and broadcast address. In which subnet is host 192.168.10.150?
Solution:
- 2^b ≥ 4 gives b = 2, so the new prefix is /26 (mask 255.255.255.192).
- Block size = 2^(32−26) = 64 addresses, 62 usable hosts.
- Subnets: .0/26 (hosts .1–.62, broadcast .63), .64/26 (.65–.126, .127), .128/26 (.129–.190, .191), .192/26 (.193–.254, .255).
- 150 lies between 128 and 191, so it is in 192.168.10.128/26.
Result: Four /26 subnets of 62 hosts each; .150 belongs to the third subnet.
import ipaddress
net = ipaddress.ip_network("192.168.10.0/24")
for sub in net.subnets(new_prefix=26):
hosts = list(sub.hosts())
print(f"{sub}: hosts {hosts[0]} - {hosts[-1]}")
print(f" broadcast {sub.broadcast_address}, {len(hosts)} hosts")
host = ipaddress.ip_address("192.168.10.150")
print(host, "is in", [str(s) for s in net.subnets(new_prefix=26)
if host in s][0])
Output
192.168.10.0/26: hosts 192.168.10.1 - 192.168.10.62
broadcast 192.168.10.63, 62 hosts
192.168.10.64/26: hosts 192.168.10.65 - 192.168.10.126
broadcast 192.168.10.127, 62 hosts
192.168.10.128/26: hosts 192.168.10.129 - 192.168.10.190
broadcast 192.168.10.191, 62 hosts
192.168.10.192/26: hosts 192.168.10.193 - 192.168.10.254
broadcast 192.168.10.255, 62 hosts
192.168.10.150 is in 192.168.10.128/26
Common mistakes
- Counting the network and broadcast addresses as usable hosts.
- Using 2^b > S instead of 2^b ≥ S, which wastes a bit.
- Placing subnet boundaries at numbers that are not multiples of the block size.
Key takeaways
- The network address is the IP address AND the mask.
- /n gives 2^(32−n) addresses and 2^(32−n) − 2 hosts.
- Borrow b bits for 2^b subnets; block size gives the subnet boundaries.
- CIDR enables flexible sizes and route aggregation; VLSM gives subnets different sizes.
Practice questions
- How many usable hosts are in a /27 subnet?
- What mask corresponds to /26?
- What is route aggregation?
Answers to the practice questions
-
- 255.255.255.192.
- Combining several network prefixes into one larger prefix in routing tables.
Sources
- Official BCA syllabus Computer Networks, course code 26BCA404DS02, Unit II
