Article
Subnet Calculator: How to Calculate a Subnet Mask and CIDR
The subnet mask is set by the CIDR prefix, the number of leading bits of an address reserved for the network. This article shows how to get the mask, network address, broadcast address and host count from a prefix, and gives four worked examples. You can check your own address in the IP subnet calculator. For 192.168.1.130/26 the network address is 192.168.1.128 and there are 62 usable hosts.
Last updated:
Find the network address, mask and host count in the IP subnet calculator. Plan a DHCP range in the DHCP range calculator.
The CIDR prefix and the subnet mask
An IPv4 address has 32 bits. The CIDR prefix after the slash tells how many leading bits belong to the network, and the subnet mask is the same split written as four decimal numbers.
addresses = 2^(32 − n)
usable hosts = 2^(32 − n) − 2
example: /26 → 2^6 = 64, hosts 62
| Prefix | Mask | All addresses | Usable hosts |
|---|---|---|---|
| /8 | 255.0.0.0 | 16,777,216 | 16,777,214 |
| /16 | 255.255.0.0 | 65,536 | 65,534 |
| /20 | 255.255.240.0 | 4,096 | 4,094 |
| /24 | 255.255.255.0 | 256 | 254 |
| /25 | 255.255.255.128 | 128 | 126 |
| /26 | 255.255.255.192 | 64 | 62 |
| /27 | 255.255.255.224 | 32 | 30 |
| /28 | 255.255.255.240 | 16 | 14 |
| /29 | 255.255.255.248 | 8 | 6 |
| /30 | 255.255.255.252 | 4 | 2 |
You subtract two addresses because the first address in the block identifies the network and the last one is the broadcast address.
Try it with an example
Example: the address 192.168.1.130 with prefix 26. The address and the prefix are already stored in the link to the calculator.
- IPv4 address
- 192.168.1.130
- CIDR prefix
- /26
- Result
- network 192.168.1.128/26, mask 255.255.255.192, broadcast 192.168.1.191, 62 hosts
Open the calculator with these numbers
The calculator reads the values from the page address and shows the result right away. You can change them freely.
How the calculator works
The calculator takes an IPv4 address with the prefix in a separate field or written as 192.168.1.42/24, and returns the mask, the wildcard mask, the network address, the broadcast address, the first and last host address, the total and usable address counts and the scope (for example a private address). Special prefixes and reserved addresses are explained in a note under the result. It does not split a network into subnets of different sizes (VLSM) or into a set number of subnets.
How to calculate the network and broadcast address
You get the network address with a bitwise AND of the address and the mask. For 192.168.1.130 and the mask 255.255.255.192 the last octet 130 AND 192 gives 128, so the network address is 192.168.1.128. The broadcast address sets all host bits to 1, which means adding the wildcard 0.0.0.63: 192.168.1.128 + 63 = 192.168.1.191.
The host range runs from 192.168.1.129 to 192.168.1.190. The address 192.168.1.130 lies in that range, so it belongs to the network 192.168.1.128/26.
How many hosts and which prefix to choose
To choose a prefix, find the smallest power of two that holds your hosts plus the network and broadcast addresses. For 50 devices you need 64 addresses, which is 2⁶, so the prefix is /26 and you get 62 hosts. For 100 devices it is /25 (126 hosts), and for 500 devices /23 (510 hosts).
Plan automatically assigned ranges in the DHCP range calculator. Related data-size conversions are in the memory unit converter.
Dotted masks, wildcard masks and shorthand
You turn a dotted mask into a prefix by counting the ones in binary. The mask 255.255.255.192 is 11111111.11111111.11111111.11000000, which has 26 ones, so the prefix is /26. The wildcard mask is its inverse (0.0.0.63) and appears in router access control lists.
An IPv6 address has 128 bits, and its shortened form is handled by the IPv6 shortening calculator. The calculator on this page works with IPv4 addresses.
Private addresses and where a subnet calculator helps
The private ranges are 10.0.0.0/8, 172.16.0.0/12 and 192.168.0.0/16. They are not routed on the internet, so in home and company networks you split them into subnets according to the number of devices. A typical home network uses 192.168.1.0/24, which is 254 hosts.
The calculator helps with router, VLAN and cloud setup. Estimate link capacity in the bandwidth calculator, packet size in the MTU calculator and transfer time in the download time calculator. Check the binary form of addresses in the binary converter.
Four worked examples
You can repeat each example in the IP subnet calculator.
1. 192.168.1.130/26
A full subnet breakdown.
- Enter the address and the prefix 26.
- Mask: 26 ones, which is 255.255.255.192.
- Network address: 130 AND 192 = 128, which is 192.168.1.128.
- Broadcast 192.168.1.191, hosts from 192.168.1.129 to 192.168.1.190, 62 in total.
2. A home network 192.168.1.42/24
The most common split.
- Enter 192.168.1.42/24.
- The mask is 255.255.255.0.
- The network address is 192.168.1.0 and the broadcast address is 192.168.1.255.
- There are 254 usable hosts.
3. A network for 50 devices
Choosing a prefix.
- You need 50 host addresses plus network and broadcast, which is 52.
- The smallest power of two is 64 = 2⁶.
- The prefix is /26.
- The mask 255.255.255.192 gives 62 hosts.
4. The mask 255.255.255.240
Converting a mask to a prefix.
- Write the last octet 240 in binary: 11110000.
- Count the ones: 24 + 4 = 28.
- The prefix is /28.
- The subnet has 16 addresses and 14 hosts.
Common mistakes when calculating subnets
- Forgetting the network and broadcast addresses — of the 64 addresses in a /26, 62 are usable.
- Confusing the prefix with the host count — /26 is the number of network bits, not 26 hosts.
- Finding the network address by division instead of AND — a bitwise AND with the mask gives the right result.
- Choosing a prefix with no room for growth — a /26 for 50 devices leaves only 12 free addresses.
- Using non-contiguous masks — a valid mask is a run of ones followed only by zeros.
- Mixing up the wildcard and the mask — the wildcard is the inverse of the mask.
- Assigning the network or broadcast address to a device — those addresses are reserved.
Frequently asked questions
How do you calculate a subnet mask?
Write n ones and 32 − n zeros, then split them into four octets. For /26 the mask is 255.255.255.192.
How many hosts are in a /24 subnet?
A /24 has 256 addresses and 254 usable hosts.
How many hosts does a /26 subnet have?
It has 64 addresses and 62 usable hosts.
How do you find the network address?
Do a bitwise AND of the IP address and the mask. For 192.168.1.130/26 the network address is 192.168.1.128.
How do you find the broadcast address?
Set all host bits to 1. For 192.168.1.128/26 the broadcast address is 192.168.1.191.
Is 255.255.255.0 a /24?
Yes. The mask 255.255.255.0 has 24 ones, so it equals the prefix /24.
Which prefix should I choose for 100 devices?
Choose /25, which gives 126 usable hosts.
Does the calculator split a network into VLSM subnets?
No. It describes one subnet for the address and prefix you enter, and splitting into subnets of different sizes must be planned by hand.
Calculate your own subnet
Enter an IPv4 address and prefix in the IP subnet calculator and read the mask, network address, broadcast address and host range.
Then plan a range in the DHCP range calculator or check IPv6 shortening.