IPv4 CIDR Calculator
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:
-
Convert the IPv4 dot-decimal notation to dot-binary notation.
192.168.0.1►11000000.10101000.00000000.00000001 -
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)./24becomes11111111111111111111111100000000Then we put dots:
11111111.11111111.11111111.00000000 -
After that, do the
ANDoperation for the binary version of the IPv4 and the binary version of the subnet mask.ANDOPERATIONS:- 1
AND1 = 1 - 1
AND0 = 0 - 0
AND1 = 0 - 0
AND0 = 0
IP:
11000000.10101000.00000000.00000001Mask:
11111111.11111111.11111111.00000000--------------------------------------------------------------
ANDRESULT:
11000000.10101000.00000000.00000000 - 1
-
Afterward, convert the
ANDresult back to dot-decimal notation. This is the first IP within the block. The HOST address.11000000.10101000.00000000.00000000►192.168.0.0 -
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.00000000►255.255.255.0 -
Then, do subtraction like so:
FULL MASK:
255.255.255.255SUBNET MASK:
255.255.255. 0---------------------------
-SUBTRACTION RESULT:
0. 0. 0.255Or, invert the subnet mask binary version, then convert it back to decimal.
11111111.11111111.11111111.00000000inverted, becomes:
00000000.00000000.00000000.1111111100000000.00000000.00000000.11111111to decimal is0.0.0.255.Same result. ✅
-
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. 0SUBTRACTION RESULT:
0. 0. 0.255---------------------------
+LAST IP:
192.168. 0.255 -
Complete.
So then192.168.0.1/24is to tell the computer that its network HOST is at192.168.0.0(and the network block is within192.168.0.0—192.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.
