A prefix leaves n host bits, and 2ⁿ − 2 addresses are usable.
The Formula on a /24
Take the network
198.51.100.0/24.
Figure 1 – Calculating usable addresses with a /24 subnet mask.
The prefix length is /24.
So:n = 32 − 24 = 8 host bits
2⁸ − 2 = 254 usable hosts
Answer the question below
How many usable hosts are in a /24 network?
One Bit Less, Half the Hosts
Each time the prefix grows by one, you give one bit to the network and take it from the hosts.
The addresses are divided by two, and the usable hosts are that number minus 2.Prefix
Subnet mask
Host bits
Addresses
Usable hosts
/24
255.255.255.0
8
256
254
/25
255.255.255.128
7
128
126
/26
255.255.255.192
6
64
62
/27
255.255.255.224
5
32
30
/28
255.255.255.240
4
16
14
/29
255.255.255.248
3
8
6
Table 1 – Addresses and usable hosts from /24 to /29.
Read the table from the hosts you need, not from the prefix.
Thirty devices fit in a /27, thirty-one do not: the first prefix with enough usable hosts is the one you pick.Answer the question below
How many usable hosts are in a /27 network?
Answer the question below
Which prefix is the smallest subnet that fits 100 hosts?
Answer the question below
Table 1 begins at /24, but the formula 2ⁿ − 2 keeps working for larger networks. How many usable hosts does a /22 network give? Answer with digits only.
Answer the question below
A VLAN must hold 255 hosts. Following the rule above (the first prefix with enough usable hosts), which prefix do you pick? Answer in the same format as Table 1, for example /26.
A mask octet can only take nine values.
Reading a Mask
A mask is a run of 1 bits followed by a run of 0 bits.
Inside one octet, the 1 bits fill from the left, so there are only nine possible octets, one per number of bits:Bits set in the octet
Mask octet
0
0
1
128
2
192
3
224
4
240
5
248
6
252
7
254
8
255
Table 2 – The nine values a mask octet can take.
Every mask is made of 255s, then one of these values, then 0s.
255.255.255.224is three full octets and 3 bits of the fourth.255.255.240.0is two full octets and 4 bits of the third.Answer the question below
Which mask octet has exactly 5 bits set?
Converting a Prefix to a Mask
Take
/20.
Twenty bits are two full octets (16 bits) plus 4 bits of the third.
Four bits set is 240, so the mask is255.255.240.0.
Now the other way. Take255.255.255.248.
Three full octets are 24 bits, and 248 is 5 bits, so the prefix is/29.
Prefix and mask are the same information written two ways: Cisco IOS asks for the mask and displays the prefix.Answer the question below
What is the subnet mask of a /20?
The table stopped at /29 because the last three prefixes are special.
A /30 is the classic link between two routers, a /31 does the same job without waste, and a /32 is one address on its own./30: Two Usable Addresses
With /30, only 2 host bits remain.

Figure 2 – Calculating usable addresses with a /30 subnet mask.
A /30 subnet provides:
1 network address
2 usable host addresses
1 broadcast address
Example: 198.51.100.0/30
Network address: 198.51.100.0
Usable IP addresses: 198.51.100.1 and 198.51.100.2
Broadcast address: 198.51.100.3
A /30 is used on point-to-point links between two routers.
Configure R1:
R1# conf t Enter configuration commands, one per line. End with CNTL/Z. R1(config)# interface g0/0 R1(config-if)# ip address 198.51.100.1 255.255.255.252 R1(config-if)# no shutdown R1(config-if)# endAnd R2:
R2# conf t Enter configuration commands, one per line. End with CNTL/Z. R2(config)# interface g0/0 R2(config-if)# ip address 198.51.100.2 255.255.255.252 R2(config-if)# no shutdown R2(config-if)# endWe can verify on R1:
R1# show ip route // Output omitted for brevity. C 198.51.100.0/30 is directly connected, GigabitEthernet0/0The routing table shows the subnet with its prefix: /30.
Answer the question below
How many usable hosts are in a /30 network?
/31: Nothing Wasted
A /30 reserves two of its four addresses, so half of every point-to-point link is lost.

Figure 3 – Calculating usable addresses with a /31 subnet mask.
RFC 3021 solves this: on a point-to-point link, both addresses of a /31 can be used.
A /31 subnet provides:
2 usable host addresses
No network address reservation
No broadcast address
Example: 198.51.100.6/31
Usable IP addresses: 198.51.100.6 and 198.51.100.7
It does the same job as a /30, and no address is lost.
Configure R1:
R1# conf t Enter configuration commands, one per line. End with CNTL/Z. R1(config)# interface g0/1 R1(config-if)# ip address 198.51.100.6 255.255.255.254 R1(config-if)# no shutdown R1(config-if)# endAnd R2:
R2# conf t Enter configuration commands, one per line. End with CNTL/Z. R2(config)# interface g0/1 R2(config-if)# ip address 198.51.100.7 255.255.255.254 R2(config-if)# no shutdown R2(config-if)# endWe can verify on R1:
R1# show ip route // Output omitted for brevity. C 198.51.100.6/31 is directly connected, GigabitEthernet0/1The routing table shows the subnet with its prefix: /31.
Answer the question below
How many usable addresses does a /31 provide for point-to-point links?
/32: One Address
A /32 holds one address.

Figure 4 – Calculating usable addresses with a /32 subnet mask.
With /32, there are 0 host bits.
The formula would give 2⁰ − 2 = −1, so it does not apply.
A /32 is a single address, not a network.
It is used for loopbacks and host routes.Answer the question below
How many host bits are in a /32?