A network prefix length calculator works out the subnet mask, network address, broadcast address, and usable host range for a given IP address and prefix length (CIDR notation). You enter an IPv4 or IPv6 address and a prefix length (e.g., 24 for 255.255.255.0), and the calculator returns the network details you need for configuring routers, firewalls, or subnets.
Formula
The calculator uses the standard CIDR (Classless Inter-Domain Routing) math. For IPv4, the prefix length p (0–32) defines the subnet mask as p consecutive 1-bits followed by (32 − p) 0-bits. The network address is the bitwise AND of the IP address and the mask; the broadcast address is the network address with all host bits set to 1. The number of usable hosts is 2(32−p) − 2 (subtracting network and broadcast addresses). For IPv6, the prefix length (0–128) works the same way, but there is no broadcast address and the host count is effectively 2(128−p).
Worked Example
Using the default values: IP = 192.168.1.0, prefix = 24.
- Subnet mask: 24 bits = 255.255.255.0 (binary: 11111111.11111111.11111111.00000000).
- Network address: 192.168.1.0 AND 255.255.255.0 = 192.168.1.0.
- Broadcast address: set the last 8 bits to 1 → 192.168.1.255.
- Usable hosts: 28 − 2 = 256 − 2 = 254 (addresses .1 to .254).
The calculator shows: network 192.168.1.0, broadcast 192.168.1.255, mask 255.255.255.0, usable hosts 254.
How Prefix Length Works
In IPv4, an IP address is a 32-bit number, usually written as four octets (e.g., 192.168.1.0). The prefix length tells you how many of those bits are the network part. The remaining bits are the host part. For example, /24 means the first 24 bits are the network, leaving 8 bits for hosts. This is equivalent to the old classful subnet mask 255.255.255.0. CIDR was introduced in 1993 to replace classful addressing, allowing more flexible allocation of address space.
For IPv6, addresses are 128 bits, written as eight groups of four hex digits (e.g., 2001:db8::/32). The prefix length works identically: /64 means the first 64 bits are the network, leaving 64 bits for the interface ID. IPv6 has no broadcast address; instead, it uses multicast and anycast, so the host count is simply 2(128−p).
How to Choose a Prefix Length
Choosing the right prefix length depends on how many hosts you need and how many subnets you want. Here are the steps:
- Count the maximum number of hosts you need in the subnet (including the network and broadcast addresses).
- Find the smallest prefix length that gives you at least that many addresses. Use the formula: usable hosts = 2(32−p) − 2.
- For example, 10 hosts → need 24 − 2 = 14 usable → /28 (16 addresses total).
- If you need multiple subnets, start with a larger prefix (e.g., /24) and borrow host bits to create smaller subnets (e.g., /26 gives 4 subnets of 62 usable hosts each).
- Always leave room for growth—choose a prefix that gives you at least 20% more addresses than you currently need.
For IPv6, the standard practice is to use /64 for every subnet because it enables Stateless Address Autoconfiguration (SLAAC). Smaller prefixes (like /127 for point-to-point links) are sometimes used, but /64 is the default.
Common Mistakes and Misconceptions
One common mistake is confusing the prefix length with the number of hosts. A /24 does not mean 24 usable hosts—it means 24 bits of network, leaving 8 bits for hosts, giving 254 usable addresses. Another mistake is forgetting to subtract two addresses (network and broadcast) in IPv4. For example, a /30 has only 2 usable addresses, which is typical for point-to-point links.
A frequent misconception is that the subnet mask must be one of the classful defaults (255.0.0.0, 255.255.0.0, 255.255.255.0). CIDR allows any prefix length from 0 to 32, so you can have a /23 (255.255.254.0) or a /27 (255.255.255.224).
Another issue is mixing up decimal and binary. When you see a subnet mask like 255.255.255.192, that is /26, not /24. Always convert the mask to binary to find the prefix length: count the consecutive 1-bits.
Prefix Length vs. Subnet Mask
The prefix length and subnet mask are two ways of expressing the same thing. The subnet mask is the dotted-decimal representation of the prefix length. For example:
- /8 → 255.0.0.0 (Class A default)
- /16 → 255.255.0.0 (Class B default)
- /24 → 255.255.255.0 (Class C default)
- /25 → 255.255.255.128
- /30 → 255.255.255.252
In routing tables, the prefix length is used to determine the network portion of a route. A router compares the destination IP with the network address using the prefix length to decide which interface to forward the packet to.
Practical Applications
You use a prefix length calculator whenever you set up a new network, assign static IPs, or design a subnet plan. For example, if you are setting up a small office with 30 devices, you might choose /27 (30 usable hosts) to minimize waste. If you are configuring a home router, the default is often /24, giving you 254 addresses.
In IPv6, you might use a /48 prefix for your site, then divide it into /64 subnets for each VLAN. A calculator helps you see how many subnets you can create and what the network addresses are.
Limitations and Accuracy
This calculator assumes standard CIDR rules. It does not account for special cases like IPv4 multicast (224.0.0.0/4) or reserved addresses (e.g., 169.254.0.0/16 for link-local). For those, the host count is not meaningful. Also, it does not handle IPv6 zone IDs (e.g., fe80::1%eth0) or IPv4-mapped IPv6 addresses.
The calculator is accurate for all valid prefix lengths (0–32 for IPv4, 0–128 for IPv6). For IPv4, a /31 prefix is sometimes used for point-to-point links, but the calculator will show 0 usable hosts because it subtracts two addresses. In practice, /31 is allowed for point-to-point links (RFC 3021), but the standard formula subtracts two. If you need /31, you can use it, but be aware of the special case.
Frequently Asked Questions
What is a prefix length in networking?
A prefix length is the number of bits in the network portion of an IP address, written as a slash followed by a number (e.g., /24). It determines the subnet mask and how many addresses are available for hosts.
How do I calculate the number of hosts from a prefix length?
For IPv4, the number of usable hosts is 2(32−prefix) − 2. For example, /24 gives 28 − 2 = 254. For IPv6, it is 2(128−prefix), but practically you use /64 for subnets.
What is the difference between /24 and 255.255.255.0?
They are the same. /24 is the prefix length, and 255.255.255.0 is the subnet mask. Both indicate that the first 24 bits of the IP address are the network part.
Why do I need to subtract 2 from the host count?
In IPv4, the first address in a subnet is the network address, and the last is the broadcast address. These cannot be assigned to hosts, so you subtract 2 from the total number of addresses.
Can I use a /31 prefix for a point-to-point link?
Yes, RFC 3021 allows /31 for point-to-point links, giving 2 usable addresses (no network/broadcast). However, many calculators and older devices still assume the −2 rule, so check your equipment.
What is the default prefix length for a home network?
Most home networks use /24, which gives 254 usable addresses. Some modern routers use /23 or /22 to allow more devices, but /24 is the most common.
Related
Formula used
in ip | IP address (e.g., 192.168.1.0) | - | 192.168.1.0 | 0 | 0 in prefix | Prefix length | bits | 24 | 0 | 32 out network | Network address | - | 192.168.1.0 | 0 out broadcast | Broadcast address | - | 192.168.1.255 | 0 out mask | Subnet mask | - | 255.255.255.0 | 0 out hosts | Usable hosts | - | 254 | 0
Each line is one input (in, sel, list) or one result (out: label, unit, formula, decimals). How the calculators work
Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.
More cards in this drawer
- Measuring Light Speed & Wavelength: How It Works
- Draco Race Blox Fruits: How to Get It
- ES File Explorer Tips & Tricks That Actually Work
- Remove Google FRP Lock on Oppo: Step-by-Step
- Forza Horizon 6: Unlock Legend Island & Earn Horizon Legend
- Clean Hair Dryer Filter: Improve Airflow