IP Subnet Calculator

Work out the network address, broadcast address, host range and mask of any IPv4 or IPv6 CIDR — and check whether an IP belongs to it. Nothing leaves your browser.

About this tool

Every IP network is a range of addresses, and the shorthand for writing that range down is CIDR: an address, a slash, and a number. 192.168.1.0/24 means "the 256 addresses whose first 24 bits are 192.168.1". That is the whole idea — and it is also why the arithmetic is easy to get wrong, because the boundaries only line up on powers of two.

This page does four things with that arithmetic. It breaks a block down into the numbers you actually need — network address, broadcast address, the first and last usable host, the netmask and its wildcard twin. It tells you what kind of address a block is, so you can see at a glance whether it is private space or something routable on the internet. It checks whether a given IP sits inside a given subnet. And it turns a plain first-to-last range back into the shortest list of CIDR blocks that covers it exactly.

IPv4 and IPv6 are both handled, and both are computed the same way — as plain integers of 32 or 128 bits. Everything runs in your browser: no address you type is sent anywhere, and nothing is logged.

Why JavaScript bitwise operators get IP subnet maths wrong

Bitwise operators in JavaScript work on 32-bit signed integers, so masking any address of 128.0.0.0 or above produces a negative number. The subnet arithmetic here uses arbitrary-precision integers instead, and one correct implementation then serves IPv4 and IPv6 alike.

The failure is deceptive precisely because it does not happen everywhere. Mask 192.168.1.10 with a /24 and the leading bit is zero, so the result looks perfect. Try 200.1.2.3 with the same mask and the top bit is set, the result goes negative, and the network address printed is nonsense.

The usual patch is to force the value back to unsigned after every single operation, which has to be remembered at every step; miss one and only some addresses break, which is the worst kind of bug to chase. Arbitrary-precision integers remove that whole category at once, and the same code then works for IPv6, where addresses are 128 bits and no 32-bit representation exists.

The address family is not guessed from the value either. A string containing a colon is read as IPv6 and one containing a dot as IPv4, and asking whether an IPv4 address lies inside an IPv6 block is reported as an error rather than as no — a silent no is what you get when the two fields were filled in the wrong order.

Leading zeros in an IP address are read as decimal, not octal

The tool reads 192.168.001.001 as 192.168.1.1, the decimal reading. Some older libraries treat a leading zero as octal, which would turn 010.0.0.1 into 8.0.0.1 — a different address, and silently so. The plain reading is the one a person typing an address expects.

The octal convention comes from a historical way of parsing dotted addresses, and it survives in some systems to this day. It means the same text can denote two different addresses depending on which software reads it, and the difference only appears when a leading zero is present.

The choice here is the plain reading: a leading zero does not change the value of a decimal number, so 001 is 1. The alternative would mean that an address copied out of a spreadsheet, where 010 is very easy to end up with, points somewhere other than where the person who typed it expects.

An octet above 255 is rejected outright, so 192.168.1.300 is an error rather than a wrapped value. The parser also insists on exactly four groups, because a three-part address is interpreted differently by different libraries and no reading of it is obviously correct.

What makes a subnet mask invalid

A mask must be a run of ones followed by a run of zeros. 255.255.255.0 is valid; 255.0.255.0 is rejected with an error instead of being counted as a /16, which is what naive bit counting would report. The check runs on the inverse of the mask, which is where a popular one-line test goes wrong.

Counting the ones in a mask is easy and produces an answer for any input, including masks that cannot occur. A mask with a hole in it describes an address set that is not a single block, so the prefix length that comes out of counting does not correspond to the mask in front of you — wrong, and confidently reported.

The test for a valid mask is usually written on the mask itself, and that version is easy to get backwards. The check belongs on the inverse: a mask whose last one is followed by a zero, inverted, is a value of the form 2 to the power k minus 1, which is what the familiar x and (x plus 1) test recognises.

Applied to the mask rather than its inverse, that test rejects the most ordinary mask there is and accepts 0.0.0.255. Masks can also be entered either way round, as a prefix length after the slash or as a dotted mask, and the dotted form is converted back through the same check, so an invalid mask is reported as a mask problem rather than reinterpreted.

/31 and /32: the two cases that break "minus 2"

On the old formula, 2 to the n minus 2, a /31 has zero usable addresses and a /32 is negative. But /31 works on point-to-point links (RFC 3021, both addresses usable), and /32 is a single-host route rather than a subnet.

The "minus 2" comes from reserving a network address and a broadcast address in every subnet. That holds down to /30: four addresses, minus two, leaves two usable. Push it to /31 and the arithmetic breaks — two addresses minus two is zero, so the classic tables mark /31 as unusable. But a point-to-point link between two routers has no need for a broadcast, so both addresses can be assigned, one to each end. RFC 3021 (2000) made that usage official.

/32 is stranger still: it is a single host, normally used as a host route or a loopback. One address, no network-versus-broadcast distinction, and no usable range at all. Treating it as a subnet and asking how many hosts it holds is meaningless — yet plenty of online calculators will still print "-1 usable addresses".

The practical consequence: planning with the classic formula makes you undercount by half when you carve point-to-point links out of a /24 as /31s. Conversely, if a tool reports "0 usable" for a /31, it is not necessarily wrong — it is applying one of two legitimate conventions. This tool uses the operational convention and calls out /31 and /32 explicitly.

Frequently asked questions

What does the number after the slash mean?

It is how many of the leading bits belong to the network — the rest identify hosts inside it. /24 keeps 24 bits for the network and leaves 8 for hosts, which is 2^8 = 256 addresses. /16 leaves 16 host bits (65,536 addresses), /25 leaves 7 (128 addresses), and so on. A bigger number means a smaller network.

Why is the usable host count two less than the total?

On an ordinary IPv4 subnet the first address is reserved to name the network itself and the last is the broadcast address that reaches every host at once, so neither can be assigned to a machine. A /24 therefore holds 256 addresses but only 254 hosts. That is also why a /30 (4 addresses) is the smallest block worth using for a normal point-to-point link — it leaves exactly 2.

Do /31 and /32 behave differently?

Yes, and this is where many calculators quietly give the wrong answer. A /32 is a single address and a /31 holds two, so the usual "subtract 2" rule would leave 0 usable hosts — clearly nonsense. RFC 3021 fixes this: on a /31 both addresses are usable, which is why modern point-to-point links use them. This tool reports 1 usable address for a /32 and 2 for a /31.

What is a wildcard mask for?

It is the netmask flipped upside down: every bit that is 1 in the mask becomes 0, and vice versa. Routers and access lists often want the wildcard form — 192.168.1.0 with a 0.0.0.255 wildcard means "anything ending in 192.168.1". Computers want the netmask; routers want the wildcard. This page shows both so you never have to invert one by hand.

How is IPv6 different?

Mostly in scale, and in one detail that trips people up. An IPv6 address is 128 bits, so even a /64 — the standard size for one LAN — holds about 1.8 × 10^19 addresses. There is also no broadcast address in IPv6 at all; the job it did is handled by multicast. So this tool shows a "last address" for IPv6 instead of inventing a broadcast that does not exist.

Is anything I type sent anywhere?

No. There is no server involved in the calculation — the whole thing is integer arithmetic running on your own device. That also means the page keeps working with no network connection, and that a private range you paste in never leaves your machine.

Related tools