Quote:
Originally Posted by acid_kewpie
and the correct CIDR would be /8: 12345678.xxxxxxxx.xxxxxxxx.xxxxxxxx
|
No, in fact there is no “correct CIDR” notation for the range you supplied (137.0.0.1-138.255.255.255). In CIDR notation, the number following the slash is the number of bits which belong to the “network part” of the address. If you say 137.0.0.0/8, you it means that the first 8 bits are set in the netmask (i.e., it is 255.0.0.0). So to determine the notation to describe a network with a given number of bits and a representative IP address, you just mask it (using a bitwise AND of the IP with the netmask).
For example, suppose I want to know the correct notation for the network of 137.123.123.123/8. Then I would do a bitwise and like so:
Code:
137.123.123.123 = 10001001.01111011.01111011.01111011
&255.000.000.000 = 11111111.00000000.00000000.00000000
137.000.000.000 = 10001001.00000000.00000000.00000000
Suppose, on the other hand, that you are given a network such as 137.0.0.0/8 and want to figure out the corresponding range. Well you must keep the first 8 bits constant, and can vary the other 24 bits (all numbers like
10001001.xxxxxxxx.xxxxxxxx.xxxxxxxx). Effectively this means that you must keep the same first number, but can change the other three numbers (i.e., all numbers from 137.0.0.0 to 137.255.255.255). Well, this is too small a range for us. What about the next-largest network (one with the first 7 bits set)? Let’s talk about 137.0.0.0/7 (or more correctly 136.0.0.0/7). This means that the first 7 bits will stay constant and the other 25 bits are changable (all numbers like
1000100x.xxxxxxxx.xxxxxxxx.xxxxxxxx). This translates to IPs where the first number is 136 or 137 and the rest of the numbers vary. This is still not the correct range, but it is the correct size. If you want a network containing the range you specified, you’ll have to go one size bigger (to 6 bits). Now, you have any number like
100010xx.xxxxxxxx.xxxxxxxx.xxxxxxxx (and the CIDR notation is 136.0.0.0/6). Unfortunately, the range is now twice the size that you intended, but it does contain all of the desired range. So the range corresponding to 136.0.0.0/6 is 136.0.0.0-139.255.255.255.
As for performance, it is obviously easier for a computer to match a range in CIDR notation than an arbitrary range. However, when your CIDR notation range is unnecessarily twice as large, it is a trade off.