Cadmeo

Subnet Calculator

192.168.1.128
Network
192.168.1.191
Broadcast
192.168.1.129
First host
192.168.1.190
Last host
255.255.255.192
Subnet mask
0.0.0.63
Wildcard
64
Total addresses
62
Usable hosts

The subnet calculator takes an IPv4 address and a prefix length and reports the network address, broadcast address, usable host range, subnet mask and wildcard mask. It handles the two edge cases most calculators get wrong, /31 and /32, which reserve no network or broadcast address.

How it works

The prefix length says how many leading bits identify the network. Everything below is arithmetic on 32-bit integers.

  • The mask is the prefix length worth of 1 bits, left-aligned: /24 is 11111111.11111111.11111111.00000000, or 255.255.255.0.
  • The network address is the IP bitwise-ANDed with the mask, which clears every host bit.
  • The broadcast address is the network ORed with the inverted mask, which sets every host bit.
  • The wildcard mask is the inverted subnet mask, used in Cisco access lists and OSPF.
  • Usable hosts is normally the total minus two, for the network and broadcast addresses.

RFC 3021 allows both addresses in a /31 to be used, because a point-to-point link has no need for a broadcast address. A /32 is a single host route. Neither subtracts two, and a calculator reporting −1 or 0 usable hosts for a /31 has not implemented the exception.

Examples

A /26 subnet

Address

192.168.1.130

Prefix

/26

Result

Network 192.168.1.128 · Broadcast 192.168.1.191 · Hosts .129 to .190 · Mask 255.255.255.192 · 62 usable

A /26 splits a /24 into four blocks of 64. The address .130 falls in the second block, which starts at .128.

A point-to-point link

Address

10.0.0.1

Prefix

/31

Result

2 total addresses, 2 usable: both ends of the link

RFC 3021 removes the network and broadcast reservation for /31, which is why router-to-router links use it and save two addresses per link.

A single host

Address

203.0.113.45

Prefix

/32

Result

1 address, 1 usable

A /32 identifies exactly one address. It appears in host routes, loopback interfaces and firewall rules for a single machine.

Frequently asked questions

Why does a /24 have 254 usable hosts rather than 256?

Because the first address in the block is the network identifier and the last is the broadcast address, and neither can be assigned to a host. 2^8 is 256, minus two leaves 254. The exceptions are /31 and /32, which reserve neither.

What is a wildcard mask for?

It is the inverted subnet mask, used by Cisco access control lists and OSPF where the convention is to specify which bits to ignore rather than which to match. The /24 mask 255.255.255.0 has the wildcard 0.0.0.255.

Why can a /31 use both addresses?

Because RFC 3021 recognised that a point-to-point link between two routers has no use for a broadcast address. There are only two devices and they can address each other directly. Using /31 instead of /30 saves two addresses on every link, which adds up across a large network.

Does entering a host address rather than the network address matter?

No. The network address is derived by masking off the host bits, so 192.168.1.130/26 and 192.168.1.128/26 produce identical results. That is deliberate, you rarely know the network address before calculating it.