I'm struggling to understand how to compute the CIDR number from an IP address for hours. Examples I've seen don't explain how the provided answer was found. For example, if I have the IP 197.18.0.0, I thought the CIDR number was 24 because 197.18.0.0 is a class C address with a subnet mask of 255.255.255.0 so the first 24 bits would be 1s. Is this answer correct? If not, please explain how to find the CIDR number in this case. Thanks.
Asked
Active
Viewed 278 times
1 Answers
0
Network classes were deprecated in 1993 by RFCs 1517, 1518, and 1519, which defined CIDR. Modern networking does not use network classes.
The CIDR number is simply the number of one bits in the network mask. You cannot get a CIDR number from an address, it comes from the network mask.
You have no idea what the number is for your example of 197.18.0.0
, but if you had the mask 255.255.255.192
, you would know that it is 26
. So, 197.18.0.0
with a mask of 255.255.255.192
would be 197.18.0.0/26
.

Ron Maupin
- 98,218
- 26
- 115
- 191
-
So, the mask `255.255.255.192` was arbitrarily chosen? – sam_smith Dec 09 '17 at 22:38
-
Yes. You can have any mask length from `0` to `32` on any network address. Basically you are saying that `X` number of address bits comprise the network number, and `32-X` number of bits are the host number within that network. See the excellent answer to [this question](https://networkengineering.stackexchange.com/q/7106/8499). You must do IP math in binary, otherwise you will make mistakes. – Ron Maupin Dec 09 '17 at 22:42
-
One more quick question. Based on my understanding of your answer, if I had the mask `255.255.255.0`, then the CIDR notation would be `24`? Thanks. – sam_smith Dec 09 '17 at 22:47
-
That is correct. `255.255.255.0` is `11111111.11111111.11111111.00000000` in binary. If you count the number of one bits, it totals `24`. The one bits are the network, and the zero bits are the host. – Ron Maupin Dec 09 '17 at 23:08