IPv4 CIDR Calculator

Last modified on


CIDR stands for Classless Inter-Domain Routing.

IPv4 CIDR notation: [IPv4 network address]/[host identifier].
For example: 192.168.0.1/24


Calculation

Let's calculate this: 192.168.0.1/24

Break it down, we have two parts: 192.168.0.1 and /24.

The 192.168.0.1 is an IPv4 dot-decimal notation. The network address.

The /24 is the subnet mask as a host identifier (to denote its own network).

This is a good explanation.

This is the mainline of how the tool above does the calculation. Steps:

  1. Convert the IPv4 dot-decimal notation to dot-binary notation.

    192.168.0.111000000.10101000.00000000.00000001
  2. Translate the subnet mask suffix, in above example: /24, into dot-binary notation.

    The total length of the notation is 32 bits (32 of 0s and/or 1s).
    Look at the number after the slash, it is 24. Meaning we create 24 of 1s from the left (24 leading 1-bits). The last 8 bits (32 - 24 = 8) are filled 0s.
    Now we have the binary version of the suffix.
    Put dot (.) to separate each segment with 8 bits interval (dot-binary notation).

    /24 becomes 11111111111111111111111100000000

    Then we put dots:

    11111111.11111111.11111111.00000000

  3. After that, do the AND operation for the binary version of the IPv4 and the binary version of the subnet mask.

    AND OPERATIONS:

    • 1 AND 1 = 1
    • 1 AND 0 = 0
    • 0 AND 1 = 0
    • 0 AND 0 = 0

    IP: 11000000.10101000.00000000.00000001    

    Mask: 11111111.11111111.11111111.00000000    

    -------------------------------------------------------------- AND

    RESULT: 11000000.10101000.00000000.00000000    

  4. Afterward, convert the AND result back to dot-decimal notation. This is the first IP within the block. The HOST address.

    11000000.10101000.00000000.00000000192.168.0.0
  5. We now need to get the last IP within the block. To do that, first convert the subnet mask dot-binary notation to dot-decimal notation.

    11111111.11111111.11111111.00000000255.255.255.0
  6. Then, do subtraction like so:

    FULL MASK: 255.255.255.255  

    SUBNET MASK: 255.255.255.  0  

    --------------------------- -

    SUBTRACTION RESULT:   0.  0.  0.255  

    Or, invert the subnet mask binary version, then convert it back to decimal.

    11111111.11111111.11111111.00000000

    inverted, becomes:

    00000000.00000000.00000000.11111111

    00000000.00000000.00000000.11111111 to decimal is 0.0.0.255.

    Same result. ✅

  7. The last IP then is calculated by adding the subtraction result number 6 above with the first IP we got from step number 4.

    STARTING IP: 192.168.  0.  0  

    SUBTRACTION RESULT:   0.  0.  0.255  

    --------------------------- +

    LAST IP: 192.168.  0.255  

  8. Complete.

    So then 192.168.0.1/24 is to tell the computer that its network HOST is at 192.168.0.0 (and the network block is within 192.168.0.0192.168.0.255).

That's the main idea for translating the /number suffix (network block) in IPv4 CIDR notation. It's not limited to this method, there are others, but the principles are like those above.