Hello! Let's continue our journey into IP subnetting.
In our last lesson, we focused on finding the boundaries of a subnet: the network address and the broadcast address. You learned the "Magic Number" method to quickly identify these two special, reserved addresses that bookend every subnet.
Today, we'll answer the crucial question that follows: "How many devices can I actually put in this subnet?" This is the core of efficient network design. Allocating a subnet that's too large wastes valuable IP addresses; one that's too small won't support your users. Your goal of optimizing a large network hinges on mastering this calculation.
Our learning outcome for this lesson is to: Determine the number of usable host addresses for any given CIDR prefix.
1. From Total Addresses to Usable Addresses
The number of available host addresses in a subnet is directly related to the length of its prefix (the CIDR value). Let's break down the logic:
- An IPv4 address is 32 bits long.
- The CIDR prefix (e.g.,
/24) tells you how many bits are fixed for the network portion. - The remaining bits are available for the host portion. The number of host bits, let's call it , is simply .
- With bits, you can create unique combinations or addresses. This is the total number of addresses in the subnet.
However, as we learned, two of these addresses are reserved:
- The first address (all host bits are 0) is the Network Address.
- The last address (all host bits are 1) is the Broadcast Address.
Therefore, the number of addresses you can actually assign to devices (PCs, servers, printers) is the total number of addresses minus these two.
This gives us our fundamental formula:
Usable Hosts =
where is the number of host bits.

2. Seeing the Formula in Action
This concept is best understood with a few clear examples. The following video from Professor Messer walks through the calculation for several common prefixes.
Calculating IPv4 Subnets and Hosts - CompTIA Network+ N10-009 - 1.7
This video segment provides a concise explanation of the formulas for calculating subnets and hosts, followed by practical examples.
Please watch from 04:39 to 08:08. Pay close attention to how he first introduces the 2^host bits - 2 formula and then applies it to calculate the usable hosts for a /24 prefix and a /26 prefix.
As you saw in the video:
- For a /24 prefix: host bits. Usable hosts = .
- For a /26 prefix: host bits. Usable hosts = .
3. A Practical Tip: Know Your Powers of Two
Since you work on the CLI, you know that speed and pattern recognition are key. To make these calculations instantaneous, it's extremely helpful to memorize the first several powers of two.
| Host Bits (h) | Total Addresses () | Usable Hosts () | Common Prefix |
|---|---|---|---|
| 1 | 2 | 0* | /31 |
| 2 | 4 | 2 | /30 |
| 3 | 8 | 6 | /29 |
| 4 | 16 | 14 | /28 |
| 5 | 32 | 30 | /27 |
| 6 | 64 | 62 | /26 |
| 7 | 128 | 126 | /25 |
| 8 | 256 | 254 | /24 |
| 9 | 512 | 510 | /23 |
| 10 | 1024 | 1022 | /22 |
| 11 | 2048 | 2046 | /21 |
| 12 | 4096 | 4094 | /20 |
*The /31 prefix is a special case used for point-to-point links and has 2 usable addresses, a concept we'll touch on later. For now, focus on prefixes /30 and larger.
4. An Authoritative Reference
The formula and logic we're using are industry standards. This Cisco document not only confirms the math but also provides comprehensive tables that you can use as a quick reference.
Understand Host and Subnet Quantities - Cisco
This support document from Cisco, titled 'Understand Host and Subnet Quantities', provides a formal explanation and useful reference tables.
First, read the final section of the document, starting with the note 'The subnet zero and all-ones subnet...'. The paragraph that follows provides Cisco's explanation of the '2^N – 2' rule. After that, skim the three tables for Class A, B, and C networks. Notice how the 'Number of Hosts/Subnet' column in each table matches the 'Usable Hosts' we calculated in our chart above. These tables are an excellent cheat sheet.
5. Practice Problems
As you requested, let's work through some problems to solidify this skill. Calculate the number of usable host addresses for each of the following prefixes. Try to do it without the reference table first, then check your work.
Questions:
- A subnet for a small office is defined with a /27 prefix. How many devices can you connect?
- The server VLAN is assigned a /23 prefix. What is the total number of assignable IP addresses?
- A point-to-point link between two core switches is needed. A /30 prefix is used. How many usable IPs are available?
- You need to create a subnet for a new department that requires at least 100 host addresses. What is the smallest prefix (i.e., largest CIDR number) you can use that meets this requirement?
Solutions:
-
/27 prefix:
- Host bits () =
- Usable hosts =
-
/23 prefix:
- Host bits () =
- Usable hosts =
-
/30 prefix:
- Host bits () =
- Usable hosts = (This is why /30s are perfect for links between just two devices).
-
At least 100 hosts:
- We need to find the smallest where .
- Let's check our powers of two:
- : (Too small)
- : (This works)
- To get 7 host bits, we need a prefix of .
- The smallest prefix we can use is /25.
Conclusion
Excellent work. You can now look at any CIDR prefix and immediately determine its capacity for host devices. This is a fundamental building block for designing efficient IP addressing schemes.
Key Takeaways:
- The number of host bits () is calculated as .
- The formula for calculating usable IP addresses in a subnet is .
- The two addresses are subtracted because they are reserved for the network address and the broadcast address.
- Knowing your powers of two makes this calculation much faster.
In the previous lesson, you learned how to find the network and broadcast addresses. In this lesson, you learned how many usable addresses fall between them. In our next lesson, we will combine these skills to identify the valid host IP address range for any given subnet, completing our foundational toolkit for analyzing any single subnet.