Subnet Calculator

Enter an IPv4 address and either a CIDR prefix like /26 or a mask like 255.255.255.0. You get the network address, the broadcast address, the usable host range and the wildcard mask, plus the binary working that produces them.

Put this calculator on your website for free

Copy one snippet and give your visitors a working Subnet Calculator.

How subnetting works

An IPv4 address is 32 bits, usually written as four numbers so humans can read it. A subnet mask splits those 32 bits into two parts: the ones on the left identify the network, and the ones left over on the right identify a host inside it. That is the whole idea. Everything else, the network address, the broadcast, the host range, the wildcard, falls out of where you put the split.

The split is written two ways for the same thing. A prefix like /26 says "the first 26 bits are network." A mask like 255.255.255.192 says the same in dotted form: 26 ones followed by 6 zeros. Neither is more correct; routers work in prefixes and older interfaces ask for masks, so this calculator takes either and shows you both.

The formula

network = IP AND mask
broadcast = network OR (NOT mask)
addresses = 2(32 − prefix)

AND keeps a bit only where both inputs have a 1, so every host bit is cleared and what remains is the network. The wildcard mask is NOT mask, the bitwise opposite, and setting every wildcard bit to 1 gives the broadcast address. The number of host bits is 32 minus the prefix, and each one doubles the size of the block, which is why subnet sizes only ever come in powers of two.

Worked example

Address 192.168.1.130 with a /26 prefix.

In binary the address is 11000000.10101000.00000001.10000010 and the mask is 26 ones then 6 zeros, 11111111.11111111.11111111.11000000.

AND them and the last 6 bits are cleared, giving 11000000.10101000.00000001.10000000, which is 192.168.1.128. Set those 6 bits to 1 instead and you get 192.168.1.191, the broadcast.

So the block holds 26 = 64 addresses, of which 62 are usable: 192.168.1.129 through 192.168.1.190. Note that the address we started with, .130, is an ordinary host inside the block rather than the block's name.

The minus-2 rule stops being true at /31

Almost every explanation of subnetting teaches "total addresses minus two", and for most of the range that is exactly right: the first address names the network and the last one is the broadcast, so a /24 gives you 254 usable hosts out of 256. The rule holds all the way down to /30, which is why /30 was for years the standard way to number a link between two routers: four addresses, two of them spent, two routers connected.

Spending half a block to connect two devices is a lot, and in 2000 RFC 3021 fixed it. On a point-to-point link there is nothing to broadcast to, so a /31 dispenses with the network and broadcast addresses entirely and both of its two addresses are usable. A /32, similarly, is a single address used as a host route.

This matters here because the arithmetic and the reality part company at the bottom of the range. Apply minus-2 to a /31 and you get zero usable hosts; apply it to a /32 and you get minus one. A negative number of hosts is a good sign that a rule has been carried past where it was ever meant to go. This calculator handles all three cases separately and tells you which one you are in.

What splitting a network actually costs

Carving one network into several is the most common reason to reach for a calculator, and the thing worth knowing before you do it is that separation costs addresses. Each new subnet needs its own network and broadcast address, so the total number of usable hosts goes down every time you split.

Split a /24 intoSubnetsUsable hosts eachUsable hosts total
nothing (leave it)1254254
/252126252
/26462248
/27830240
/281614224
/29326192
/30642128

Cut a /24 all the way down to /30 links and you keep 128 of the original 254 addresses: half the network pays for the boundaries. That is often a completely reasonable price for keeping things separate, and plenty of well-run networks do exactly this. It is just better to choose it deliberately than to discover it once the addresses run out.

A few things that trip people up

The class letters are history, not rules. Classful addressing, where 10.x.x.x was automatically a /8 and 192.168.x.x a /24, was replaced by CIDR in 1993 (RFC 1519). CIDR is what lets a network be any prefix length at all. The class letters survive in exams and conversation, and they explain why home networks so often start with 192.168, but nothing routes by them any more.

A wildcard is not a mask. Cisco access lists and OSPF network statements are written with wildcard masks, the bitwise opposite of a subnet mask, so 0.0.0.255 in an ACL means the same range as 255.255.255.0 in an interface config. Pasting one into the other field is an easy slip and the numbers look plausible either way, so this calculator spots the inversion and says so instead of quietly computing the wrong network.

Leading zeros are genuinely ambiguous. Write 192.168.001.010 and different software disagrees about what you meant: some libraries read a leading zero as octal, making 010 the number 8, while others read it as decimal 10. Same text, two different hosts. This has been the root of real security bugs, so rather than pick one interpretation this calculator asks you to write the address without the zeros.

Frequently asked questions

How do I calculate a subnet by hand?

Write the IP address and the subnet mask in binary, then AND them together bit by bit: a bit survives only where both are 1. The result is the network address. Every bit the mask does not cover is a host bit, and setting them all to 1 gives the broadcast address. This calculator shows those steps with your own numbers so you can follow the same method on paper.

Why is it total addresses minus 2?

In a normal subnet the first address identifies the network itself and the last is the broadcast address, so neither can be assigned to a device. A /24 holds 256 addresses and 254 usable hosts. This is true down to /30, and then it stops being true: see the /31 question below.

How many usable hosts does a /31 have?

Two. A /31 has no network or broadcast address at all, so both of its addresses are assignable. RFC 3021 defines this specifically for point-to-point links, where the older practice of using a /30 wasted two addresses out of every four. Calculators that apply the minus-2 rule everywhere report 0 usable hosts for a /31, and by the same arithmetic they report -1 for a /32.

What is a wildcard mask?

It is the bitwise inverse of the subnet mask: where the mask has 1 the wildcard has 0, and vice versa. A /24 mask of 255.255.255.0 has a wildcard of 0.0.0.255. Cisco access lists and OSPF statements are written with wildcards, which is why people sometimes paste one into a subnet field by mistake. This calculator recognises the swap and tells you it happened rather than failing.

Why was my subnet mask rejected?

A subnet mask has to be a solid run of ones followed by a solid run of zeros, because that is what lets a router match a prefix in a single operation. Something like 255.255.0.255 has a gap in the middle, and no router will accept it. It is a natural thing to type and an easy one to misread, so the calculator names the problem instead of quietly rounding it to something else.

Are IP address classes still used?

Not for routing. Classful addressing was replaced by CIDR in 1993 (RFC 1519), which is what lets a network be any prefix length instead of a fixed /8, /16 or /24. The old class letters still show up in exams and in conversation, and they explain why so many home networks start with 192.168, so the calculator reports the historical class while sizing everything from the prefix you actually gave it.

What does it cost to split a network into smaller subnets?

Addresses, because every new subnet needs its own network and broadcast address. Splitting a /24 into four /26 subnets turns 254 usable hosts into 248, so 6 of them pay for the split. That is usually a fine trade for the separation you get, but it is worth seeing the number rather than being surprised by it.

Why does the calculator refuse leading zeros?

Because they are genuinely ambiguous. Some libraries read 010 as octal, meaning 8, and others read it as decimal 10, so the same written address can point at two different hosts. Rather than guess which you meant, the calculator asks you to write it without the zero. This ambiguity has been the basis of real security bugs, so it is not a pedantic objection.

Related calculators