IP Subnet Calculating

From CTWUG Wiki
Jump to: navigation, search

This tutorial will show you how to calculate available IP's in any subnet without using any sort of tool.

First you will need to create a table which you will use to refer to:

Starting on the TOP row from the RIGHT, you start with "1" in the first column. You double that to get your second column which is obviously "2" and double the second column to get the third and so on until you have 8 colums.

It will look like this

128 | 64 | 32 | 16 | 8 | 4 | 2 | 1
Then for the second row, starting from the LEFT now, you start with the number above. To get the next column, you take the number from column 1 row 2 and add the number above where the next number must be. So Column 1 will be 128. Above column 2 is 64 so column 2 will be 128 + 64 = 192 and so on
Your whole table will then look like this

128 64 32 16 8 4 2 1
128 192 224 240 248 252 254 255

There are 2 different formats of subnets you can get. Either /28 or 255.255.255.240, for example.

Now I wont get into too much details regarding bits, as I dont fully understand it, but if you look at the table above, reading from left to right... 255 is in column 8. This refers to the bits so 255 is 8 bits.

So in the example, 255.255.255.240 is a /28 subnet because 255 is 8 bits ( so 8 x 3 = 24 ). 240 is in column 4 so thats another 4 bits. 24 + 4 = 28 therefore /28.

the reverse could be said if you were given /24 and had to convert back to windows format in order to use the above table. Luckily 24/8 = 3 so you would have 3 sets of the number under the 8th column. So /24 would be 255.255.255.0.

Another example lets say a /25. 8 goes into 25, 4 times with a remainder of 1. so it would be 255.255.255.xxx. Because there is still 1bit left we refer to the table. What number is in row 2 of column 1 ( reason for column 1 is you only have 1bit remaining... if it was 2 bits you would use column 2 ). The answer is 128. So your final format will be 255.255.255.128 for a /25.


NOW TO CALCULATE IP"S:

Lets say for this How-to you are asked to work out the available IP's for 172.18.1.0/24.

Well we now know how to get back to the windows format of subnets so already /24 is 255.255.255.0

Now we look at row 1 of the table ( these numbers indicate the increment ). What number is above 255 and the answer is 1. This means the ip block will increment by 1 for each new block. The number to increment is decided by the which is the last non 0 number in the subnet. In this case the last non zero is the 3rd number. 255.255.255.0

Now looking at your ip block, each new block starts with an increment of one. So for example:

172.18.1.0 - Block 1 172.18.2.0 - Block 2 - 3rd number increments by 1. 172.18.3.0 - Block 3 etc etc

Seeing these different block you can also see that block one has 255 IP's ( obviously losing 1 to network/broadcast but they are still ip's )
I hope this makes sense to some of those that are required to calculate IP's available in a subnet without an online tool.
Feel free to try it out and if you have any questions just ask as to me it currently makes sense


THE EASY CHEAT METHOD

The following is basically a cheat method, which doesn't require one to understand what is going on, like myself, but if you are required to know things like "host bit length" etc then this is not the right how to for you.

FORMULA: Max Hosts = 2^n ( 2 to the power of n ) where n is the host bit length.

Now to get the host bit length is easy but requires the mask length ( aka /24 etc )

You would basically draw a table with 2 rows and 32 columns ( because you have 32 mask lengths ). Row 1 would have your mask length, starting left to right from 32 all the way to zero. Row 2 would have your bit length starting left to right from 0 to 32. So would look something like this

32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 ...
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 ...

So easily we can see a /24 would have max hosts = 2^8 = 256 IP's.

And if you wanted to know how many ip's are available in the world of the internet which is /0 then its 2^32 = 4294967296 ( FUN FACT ) SIMPLE!