IP fundamentals

Convert IPv4 netmasks to CIDR prefixes

A valid contiguous IPv4 mask has leading ones followed by zeros; the number of ones is the CIDR prefix length.

Updated

Read an octet

255 is 11111111; 224 is 11100000. A mask of 255.255.255.224 therefore has 8+8+8+3 = 27 leading ones.

Calculate the interval

A /27 has five host bits and 32 addresses. 192.0.2.37/27 belongs to 192.0.2.32 through .63. In an ordinary LAN, .33 through .62 are usable host addresses.

Reject non-contiguous masks

255.0.255.0 contains ones after zeros and is not a valid CIDR mask. The edge cases /0 and /32 are valid prefixes, but their use differs from a normal LAN subnet.

Worked example: /27

The mask 255.255.255.224 contains 24 one bits in its first three octets and three more in the last. The block size is 32. Address 192.0.2.77 belongs to 192.0.2.64/27, with the broadcast at .95; ordinary usable host addresses span .65 through .94.

Step-by-step example

Convert 255.255.255.224 into prefix length, wildcard and host capacity.

  1. 01

    Convert to binary

    Each octet has eight bits. 255 is eight ones; 224 is 11100000. A valid contiguous subnet mask has all its ones before all its zeros.

    255
    11111111
    255
    11111111
    255
    11111111
    224
    11100000
    255
    11111111
    255
    11111111
    255
    11111111
    224
    11100000
    Illustration · example, not a live result
  2. 02

    Count fixed bits

    Three full octets give 24 ones and the final octet adds three: /27. Five bits remain for addresses, so 2^5 gives 32 addresses.

    Network bits
    24 + 3 = 27
    Host bits
    32 − 27 = 5
    Addresses
    32
    Illustration · example, not a live result
  3. 03

    Verify the wildcard

    Invert every bit of the mask. The wildcard is 0.0.0.31. Enter the mask into Netmask Converter and verify all fields. On an ordinary /27 IPv4 LAN, 30 addresses are usable for hosts.

    Netmask
    255.255.255.224
    CIDR
    /27
    Wildcard
    0.0.0.31
    Illustration · example, not a live result

Check your understanding

A mask such as 255.0.255.0 is not a contiguous CIDR subnet mask and must be rejected.

Try this tool →
Working through a learning path?

Record your own progress on this browser. No account required.

Learning paths →

Try this

Enter 255.255.255.224 in the netmask converter and compare the resulting wildcard and binary.

IPv4 netmask converter →

Technical references