IPv4 subnet calculator
Enter an IP address with a CIDR prefix, like 192.168.1.10/24, to see the network, broadcast address, mask and usable host range.
This tool runs in your browser. We never send what you type or paste to a server.
CIDR cheat sheet
| Prefix | Subnet mask | 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 |
| /22 | 255.255.252.0 | 1,024 | 1,022 |
| /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 |
| /31 | 255.255.255.254 | 2 | 2 (point-to-point, RFC 3021) |
| /32 | 255.255.255.255 | 1 | 1 (single host) |
Private address ranges
10.0.0.0/8,172.16.0.0/12and192.168.0.0/16are private (RFC 1918) and not routed on the internet.100.64.0.0/10is shared address space used by carrier-grade NAT.127.0.0.0/8is loopback;169.254.0.0/16is link-local, used when DHCP fails.
Example
192.168.1.10/24
network 192.168.1.0
broadcast 192.168.1.255
hosts 192.168.1.1 – 192.168.1.254 (254 usable)
mask 255.255.255.0
How a CIDR mask works
An IPv4 address is 32 bits. The prefix length says how many of them, counted from the left, name the network; the rest number the hosts inside it. A /26 mask is 26 ones followed by 6 zeros, which is 255.255.255.192. The calculator then does two bitwise operations, which you can see in its binary view:
- network = address AND mask (the host bits are cleared)
- broadcast = network OR wildcard (the host bits are all set), where the wildcard is the mask inverted
For quick sums in your head, find the octet where the mask stops being 255 and subtract its value from 256. That is the block size, and networks start at multiples of it. A worked example with 172.16.45.200/20: the mask is 255.255.240.0, so the third octet changes in blocks of 256 − 240 = 16. The multiple of 16 at or below 45 is 32, so the network is 172.16.32.0, the next one starts at 172.16.48.0, and the broadcast is 172.16.47.255. That leaves 212 − 2 = 4,094 hosts, from 172.16.32.1 to 172.16.47.254.
Subnetting in code
Python's standard ipaddress module does everything the calculator does, plus splitting and membership tests:
net = ipaddress.ip_network('192.168.1.0/26')
print(net.netmask, net.hostmask) # → 255.255.255.192 0.0.0.63
print(net.broadcast_address) # → 192.168.1.63
print(net.num_addresses - 2) # → 62 usable hosts
hosts = list(net.hosts())
print(hosts[0], hosts[-1]) # → 192.168.1.1 192.168.1.62
Splitting a /24 into four equal parts means borrowing two host bits, giving four /26 networks of 64 addresses each:
for sub in ipaddress.ip_network('192.168.1.0/24').subnets(new_prefix=26):
print(sub)
# → 192.168.1.0/26
# → 192.168.1.64/26
# → 192.168.1.128/26
# → 192.168.1.192/26
print(ipaddress.ip_address('10.20.30.40') in ipaddress.ip_network('10.0.0.0/8')) # → True
print(ipaddress.ip_address('172.32.0.1').is_private) # → False 172.16.0.0/12 ends at 172.31.255.255
JavaScript has no built-in IP type, so you do the bit arithmetic yourself. Bitwise operators work on signed 32-bit integers, so any address from 128.0.0.0 upwards comes out negative unless you finish with >>> 0:
const toInt = (ip) => ip.split('.').reduce((n, x) => n * 256 + Number(x), 0);
const toIp = (n) => [24, 16, 8, 0].map((s) => (n >>> s) & 255).join('.');
const mask = (prefix) => (prefix === 0 ? 0 : (0xffffffff << (32 - prefix)) >>> 0);
const ip = toInt('10.1.2.200'), m = mask(25);
console.log(toIp(m)); // → 255.255.255.128
console.log(toIp((ip & m) >>> 0)); // → 10.1.2.128 network
console.log(toIp((ip | ~m) >>> 0)); // → 10.1.2.255 broadcast
console.log(toInt('192.168.1.1') & 0xffffff00); // → -1062731520 bitwise ops are signed 32-bit
console.log((toInt('192.168.1.1') & 0xffffff00) >>> 0); // → 3232235776 >>> 0 makes it unsigned again
Gotchas
- Host bits in a network. 192.168.1.10/24 is a host address with its prefix, not a network. Firewalls and cloud consoles often want 192.168.1.0/24, and Python raises
ValueErrorunless you allow it:print(ipaddress.ip_network('192.168.1.10/24', strict=False)) # → 192.168.1.0/24 without strict=False this raises ValueError print(ipaddress.ip_interface('192.168.1.10/24').network) # → 192.168.1.0/24 - 172.16.0.0/12 is larger than it looks. It runs from 172.16.0.0 to 172.31.255.255, so 172.20.x.x is private and 172.32.x.x is not.
- Cloud networks keep more addresses back. AWS VPCs and Azure virtual networks reserve five addresses in every subnet (the first four and the last), so a /28 there gives 11 usable hosts, not 14.
- Overlapping ranges. Home routers almost all use 192.168.0.0/24 or 192.168.1.0/24. If an office network or VPN uses the same range, traffic for those addresses stays on the local network. Choosing an unusual block inside 10.0.0.0/8 avoids most clashes.
- No prefix given. If you type a bare address, the calculator assumes /24 and says so. You can also type a dotted mask instead of a prefix, as in
10.0.0.5 255.255.0.0; masks whose 1 bits are not contiguous are rejected.
Questions
Why are two addresses not usable?
In a normal subnet, the first address identifies the network and the last is the broadcast address, so neither can be given to a device. /31 and /32 are special cases.
What is a wildcard mask?
The inverse of the subnet mask (for /24, 0.0.0.255). Cisco access lists and OSPF use it.
How many hosts fit in a /26?
64 addresses, of which 62 are usable: the first is the network address and the last is the broadcast address. A /31 is a special case used for point-to-point links, where both addresses are usable.
How do I tell if two IP addresses are on the same subnet?
AND each address with the subnet mask. If the results are equal, they share a network. For 192.168.1.20 and 192.168.1.200 with a /25 mask, the network parts are 192.168.1.0 and 192.168.1.128, so they are on different subnets even though they share the first three octets.
Is /24 the same as 255.255.255.0?
Yes. The prefix length counts the 1 bits in the mask, and 255.255.255.0 is 24 ones followed by 8 zeros. The calculator accepts either form.
Does the subnet calculator support IPv6?
No, it works with IPv4 only. IPv6 uses the same prefix idea, but subnets are normally /64 and there is no broadcast address. Python's ipaddress.ip_network handles both versions.