# Compute CIDR number from IP

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.

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.
• So, the mask 255.255.255.192 was arbitrarily chosen? – sam_smith Dec 9 '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. You must do IP math in binary, otherwise you will make mistakes. – Ron Maupin Dec 9 '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 9 '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 9 '17 at 23:08