Counting Hosts in a Subnet
Calculate how many usable addresses a subnet provides.
Counting Hosts in a Subnet is a free Network+ Academy lesson on CoddyKit — lesson 3 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Network+ Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Hosts Come From Host Bits
The number of addresses in a subnet depends entirely on the host bits — the 0 bits in the mask. The more host bits, the more addresses.
If you know the prefix, you know the host bits: subtract the prefix from 32. A /24 has 32 minus 24 = 8 host bits.
The Power of Two Formula
The total number of addresses in a subnet is 2 to the power of the host bits. With 8 host bits, that is 2^8 = 256 total addresses.
This count includes every possible combination of host bits, from all zeros to all ones — including the special network and broadcast addresses.
total = 2 ^ (32 - prefix)
/24 -> 2 ^ 8 = 256Subtract Two for Usable Hosts
Two addresses in every subnet are reserved: the network address (all host bits 0) and the broadcast address (all host bits 1). Neither can be assigned to a device.
So usable hosts = total minus 2. A /24 gives 256 - 2 = 254 usable hosts, the figure you will quote most often.
The Full Usable Formula
Combine the steps into one rule: usable hosts = 2^(32 - prefix) - 2.
- /24 → 2^8 - 2 = 254
- /25 → 2^7 - 2 = 126
- /26 → 2^6 - 2 = 62
Each step up in prefix roughly halves the usable hosts, since you remove one host bit.
Small Subnet Examples
Tiny subnets are common for router links:
- /30: 2^2 - 2 = 2 usable hosts — perfect for a two-router point-to-point link.
- /29: 2^3 - 2 = 6 usable hosts.
- /28: 2^4 - 2 = 14 usable hosts.
These efficient blocks waste almost no addresses.
Large Subnet Examples
Smaller prefixes hold many hosts:
- /16: 2^16 - 2 = 65,534 usable hosts.
- /22: 2^10 - 2 = 1022 usable hosts.
- /20: 2^12 - 2 = 4094 usable hosts.
Choosing the right size avoids both running out of addresses and wasting them.
The /31 Special Case
A /31 normally would give 2^1 - 2 = 0 usable hosts, which seems useless. A special rule (RFC 3021) lets a /31 be used on point-to-point links with exactly 2 usable addresses and no broadcast.
The exam may mention this; just remember a /31 is a modern, efficient choice for router-to-router links.
A /32 Single Host
A /32 has zero host bits, representing a single specific address. It is used in firewall rules, loopback interfaces, and host routes.
You do not count usable hosts for a /32 in the usual way — it simply identifies one exact address rather than a range of devices.
Right-Sizing a Subnet
To pick a prefix, find the smallest subnet that still fits your hosts plus the two reserved addresses. Need 50 hosts? A /26 (62 usable) fits; a /27 (30) does not.
Always round up to the next size and leave room for growth, but avoid grabbing far more than you need and wasting address space.
Quick Estimation Trick
For fast mental math, memorize key powers of two: 2^6=64, 2^7=128, 2^8=256. Then subtract 2.
If asked how many hosts fit a /27, recall 2^5 = 32, minus 2 = 30. Building this reflex makes subnetting questions quick to answer under exam time pressure.
Putting Counts to Use
Counting hosts tells you whether a subnet meets a requirement and how many addresses remain free. It is the metric that drives every subnet-sizing decision.
Next you will use these counts to actually carve one network into several subnets, completing the core subnetting skill.
Quick Check
Calculate usable hosts.
Recap
You learned to count subnet hosts.
- Host bits = 32 - prefix.
- Total addresses = 2^(host bits).
- Usable hosts = 2^(32 - prefix) - 2 (minus network and broadcast).
- /24 = 254, /26 = 62, /30 = 2 usable hosts.
- Special cases: /31 (2 hosts, point-to-point) and /32 (single address).
Frequently asked questions
Is the “Counting Hosts in a Subnet” lesson free?
Yes — the full text of “Counting Hosts in a Subnet” is free to read here on the web, and the Network+ Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Network+ Academy course, upgrade to CoddyKit PRO.
What will I learn in “Counting Hosts in a Subnet”?
Calculate how many usable addresses a subnet provides. You practise Network+ Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Network+ Academy?
No prior experience is required. Network+ Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 3 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Counting Hosts in a Subnet” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Network+ Academy lesson?
Yes. Every Network+ Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- What a Subnet Mask Does
- Reading CIDR Slash Notation
- Counting Hosts in a Subnet
- Splitting a Network Into Subnets