IPv4 Subnet Calculator

Calculate the network, broadcast, first and last usable host, netmask and total hosts for any IPv4 CIDR or IP-with-mask.

Plan subnets without the mental math. Enter an IPv4 address with a CIDR prefix (like 192.168.1.10/24) or a dotted netmask, and get the network and broadcast addresses, the first and last usable hosts, the netmask and how many hosts fit. Computed locally.

Network address
Broadcast address
First usable host
Last usable host
Netmask
Usable hosts

Reading a subnet

What the prefix length actually fixes

A subnet is a base address plus a prefix length. The prefix says how many of the 32 bits are pinned down as the network identifier; whatever remains is free to enumerate hosts. A /24 pins the first 24 bits, leaving 8 host bits and therefore 256 addresses. Each bit you add to the prefix halves the block: /25 is 128 addresses, /26 is 64, and so on.

The netmask is the same statement written as an address, with the fixed bits set to 1 — 255.255.255.0 is 24 ones followed by 8 zeros. The wildcard mask is its inverse and marks the host portion; ACLs on Cisco gear are written with wildcards rather than netmasks, which trips up people moving between vendors.

Network, broadcast, and the hosts between

Set every host bit to 0 and you get the network address, the lowest address in the block. Set them all to 1 and you get the broadcast address, the highest. Neither can be assigned to an interface, which is where the familiar "subtract two" comes from: a /24 has 256 addresses but only 254 usable hosts.

In practice a third address is usually gone too, because the router or default gateway takes one — conventionally the first or last usable address. That is a local convention, not a rule, but it is worth budgeting for when you size a subnet.

The /31 and /32 exceptions

The subtract-two rule breaks at the small end. A /32 is a single address with no host bits at all, used for loopbacks, host routes and certificate SANs. A /31 has just two addresses, and RFC 3021 allows both to be used on a point-to-point link precisely because a link with exactly two endpoints has no need for a broadcast address. Before RFC 3021 people wasted a /30 on every link, burning two addresses out of four.

CIDR notation or a dotted mask

Both describe the same thing and this calculator accepts either. 192.168.1.0/24 and 192.168.1.0 255.255.255.0 produce identical results. Note that a legal netmask must be a contiguous run of ones followed by zeros — something like 255.0.255.0 is not a valid mask, and a calculator that silently accepts it will give you nonsense.

Open-source note: implemented in vanilla JavaScript with no third-party libraries.

FAQ

Why are two addresses subtracted from the total?
The first address identifies the network and the last is the broadcast address, and neither can be assigned to a host. A /24 therefore offers 256 - 2 = 254 usable addresses.
Can I enter a dotted mask instead of a prefix?
Yes. 192.168.1.0/24 and 192.168.1.0 255.255.255.0 produce identical results. An address with no mask at all is treated as a /32.
What happens with a /31?
RFC 3021 allows /31 on point-to-point links, where both addresses are usable and there is no broadcast. The calculator reports two usable hosts rather than zero.
Why was my mask rejected?
A valid mask is an unbroken run of 1 bits followed only by 0 bits. Something like 255.255.0.255 has a gap, so no prefix length corresponds to it.
What is the difference between the network address and the first host?
The network address is the base of the block; the first host is the next address up. For 192.168.1.0/24 they are 192.168.1.0 and 192.168.1.1.
Is this useful for VLSM planning?
Yes. Work out the block you need at each prefix length, then check that the resulting ranges do not overlap before you assign them.