CIDR to Netmask Converter

Enter a CIDR prefix like 24 or a netmask, then pick the direction.

How it is calculated

In the prefix-to-mask direction the tool sets the first p bits of a 32-bit number to 1 and writes the result as four decimal octets. The wildcard mask is the same number with every bit flipped. The host count is 232−p − 2, because the first address of the block is the network address and the last is the broadcast address. Two special cases follow RFC 3021: a /31 is shown as 2 usable hosts (a point-to-point link) and a /32 as 1 host. The prefix may be typed with or without a leading slash and must be 0 to 32. In the mask-to-prefix direction the four octets are turned into bits and counted; the mask must be four numbers from 0 to 255 whose bits are all 1s followed by all 0s, otherwise nothing is returned. This covers IPv4 only.

Worked example

Take prefix 26 in the prefix-to-mask direction. 26 ones followed by 6 zeros gives 11111111.11111111.11111111.11000000, which is 255.255.255.192, shown as 255.255.255.192. The wildcard is the inverse: 0.0.0.63. Host bits = 32 − 26 = 6, so 26 − 2 = 64 − 2 = 62 usable hosts. The tool reports 62 usable hosts.

Try this example →

Common mistakes

  • Typing a mask while the direction is set to prefix-to-mask. Entering 255.255.255.0 there gives no result; switch the direction to mask-to-prefix first.
  • Typing a prefix in the mask-to-prefix direction. A plain number like 24 is not a dotted mask and gives no result.
  • Entering a non-contiguous mask such as 255.0.255.0. Subnet masks must be ones followed by zeros, so this is rejected, and a prefix above 32 is rejected too.
  • Reading the wildcard mask as another subnet mask. It is the bitwise inverse (0.0.0.63 for /26), the form used in access lists, not a mask you assign to an interface.
  • Assuming every subnet loses two addresses. A /31 lists 2 usable hosts and a /32 lists 1, because those prefixes have special rules, whereas a /30 gives 2 and a /26 gives 62.

About this calculator

CIDR notation (Classless Inter-Domain Routing) expresses an IPv4 subnet mask as a prefix length — the number of leading 1-bits in the 32-bit mask — written after a slash, such as /24. A /24 prefix means the first 24 bits are network bits and the remaining 8 are host bits, which translates to the dotted-decimal mask 255.255.255.0; converting in the other direction, a dotted mask is read bit by bit to recover its prefix length. The number of usable host addresses in a subnet is 2^(32−prefix) − 2, subtracting the network address and broadcast address that can’t be assigned to a host.

The wildcard mask — the bitwise inverse of the subnet mask — is used separately in access control lists and routing configurations (notably on Cisco IOS) where matching rules are expressed as “don’t care” bits rather than network/host bits. Network engineers and system administrators move between prefix length, dotted-decimal mask, host count, and wildcard mask constantly when planning subnets, writing firewall rules, or configuring routers; this calculator converts a CIDR prefix (or a netmask) into all of these related values.

Was this helpful?

You can pick up to 3 reactions.

Comments (1)

  • Editorial team

    The wildcard line is the one you paste into Cisco-style access lists and OSPF network statements, where the mask is written inverted. And on router-to-router links, the /31 result of 2 usable hosts follows RFC 3021, which saves addresses compared with /30, though some older gear may not accept it. Would you like IPv6 prefixes added as well?

Popular calculators

All Calculators