IP address notation
IP range specifications are weird; they’re actually binary, and we use something called ‘dot decimal notation’ and convert them to decimal to make them a bit easier to read.
For example: the IP address 127.0.0.1 is actually a binary number with 32 numerals - or bits:
01111111000000000000000000000001
The largest possible value of that 32 bit number is just a bunch of ones:
11111111111111111111111111111111
Just like, the biggest decimal number you can write given 32 digits is a bunch of nines:
99999999999999999999999999999999
What if you want to express a range of values? (Remember, this was all developed when space was limited and every bit was precious.) In order to express a range of possible values, the most obvious method is to write down the number of bits to ignore at the end, and we can do this by just ‘masking off’ the numbers to keep. We can use 9
to indicate keep
and 0
to indicate ignore
. For example, using decimal numbers:
4294967296
9999999000
That means, a range of any number between 4,294,967,000
and 4,294,967,999
. If we want to get concise, we can then just say the range by saying how many digits to ‘mask off’ - in this example, three:
4294967296/3
In binary, we do it this way:
11111111111111111111111111111111
11111111111111111111111100000000
and that would become the range:
11111111111111111111111100000000 - 11111111111111111111111111111111
And we can shorten this by just writing down the number of binary digits we want to keep, instead of counting them all out. Note: we write down the kept digits, not the masked-off digits
11111111111111111111111111111111/8
But that’s really annoying for humans to deal with. So let’s convert this to decimal. And, it’s also really annoying to deal with one big decimal number, so let’s split it up.
We can split that 32 bit binary number four ways evenly, like so:
11111111.11111111.11111111.11111111
Then we convert each of those smaller numbers separately into decimal notation: b11111111 = d255
255.255.255.255
Now we have a normal-looking IP address:
01111111000000000000000000000001
01111111.00000000.00000000.00000001
127.000.000.001
And what does the masking look like now?
address: 127.000.000.001
masking: 255.255.255.000
Now we can make it more human-readable by removing those extra pesky zeros, and using the shortened mask notation to note down the number of digits we’re keeping:
127.0.0.1/8
…and that’s where IP address notation comes from. Or, at least, version 4. IP Version 6 is so much more fun!
¯\_(ツ)_/¯