How to Calculate Host Bits in CIDR Subnet Calculation
- rajatpatyal
- Mar 10
- 1 min read
In CIDR (Classless Inter-Domain Routing), an IP address consists of 32 bits (for IPv4), divided into:
Network bits (define the network)
Host bits (define devices within the network)
Formula to Calculate Host Bits
Host Bits=32−CIDR Prefix\text{Host Bits} = 32 - \text{CIDR Prefix}
Where CIDR Prefix (e.g., /24) represents the number of network bits.
Step-by-Step Example
1. Find the Host Bits
Let’s say we have a CIDR /26:
Host Bits=32−26=6\text{Host Bits} = 32 - 26 = 6
2. Calculate Total Hosts
Total Hosts=2Host Bits\text{Total Hosts} = 2^{\text{Host Bits}}
For /26:
26=64(Total IPs in subnet)2^6 = 64 \quad (\text{Total IPs in subnet})
3. Find Usable Hosts
Since two addresses are reserved (network ID and broadcast address), the number of usable hosts is:
Usable Hosts=2Host Bits−2\text{Usable Hosts} = 2^{\text{Host Bits}} - 2
For /26:
64−2=62(Usable Hosts)64 - 2 = 62 \quad (\text{Usable Hosts})
Quick Reference Table
CIDR | Network Bits | Host Bits | Total IPs | Usable Hosts |
/30 | 30 | 2 | 4 | 2 |
/29 | 29 | 3 | 8 | 6 |
/28 | 28 | 4 | 16 | 14 |
/27 | 27 | 5 | 32 | 30 |
/26 | 26 | 6 | 64 | 62 |
/25 | 25 | 7 | 128 | 126 |
/24 | 24 | 8 | 256 | 254 |
/16 | 16 | 16 | 65,536 | 65,534 |
How to Choose CIDR for a Required Number of Hosts
If you need X hosts, find the smallest CIDR where:
2Host Bits−2≥X2^{\text{Host Bits}} - 2 \geq X
🔹 Example: Need 500 hostsFind smallest CIDR where:
2n−2≥5002^n - 2 \geq 500
2^8 = 256 - 2 = 254 (Too small)
2^9 = 512 - 2 = 510 (Enough!)
✅ CIDR /23 supports 510 usable hosts.
Comentários