Decimal and Binary Conversion of IP Addresses
All network professionals need to have a firm grasp of the principles behind IP addressing. This includes understanding how an IP address is associated with a specific network. This is done by using a network address and CIDR to calculate the Network Address, Network Range and Broadcast Address. But the first place we need to start is with a simple understanding of an IP address and it?s conversion to binary and decimal.
An IP address is broken into dotted octet notation. Each octet is expressed as a decimal value from Zero to 255. Since computers start counting from zero this gives us 256 possible values for each octet. Each octet value represents its binary equivalent.
Calculating the decimal value of an IPv4 address is easy. If we were to number the octets from left to right and break them into variables called $octet1, $octet2, $octet3 and $octet4, we can use the following formulas to convert each octet into its decimal value and then add each decimal value to achieve the decimal equivalent for the IP address:
$octet1 x (256^3) = $decimal1
$octet2 x (256^2) = $decimal2
$octet3 x (256) = $decimal3
$octet4 = $decimal4
$decimal1 + $decimal2 + $decimal3 + $decimal4 = $decimal_equivalent
For example, converting IP Address 192.168.1.16 to its decimal equivalent would look like this:
192 x (256^3) = 3221225472
168 x (256^2) = 11010048
1 x 256 = 256
16 = 16
3221225472 + 11010048 + 16 = 3232235792
The decimal equivalent of 192.168.1.16 is 3232235792.
Converting an IP address to binary is also easy. We can break down each octet into 8 bits and concatenate (join) the results when we are finished.
Each bit is represented by a 1 (one) or 0 (zero). The value 1 represents on and the value 0 represents off. A simple method for converting from an IP address to binary is to use a chart to represent the decimal to binary values for each octet.
Here?s the chart:

8 
7 
6 
5 
4 
3 
2 
1 

Decimal 
128 
64 
32 
16 
8 
4 
2 
1 
Value 
Binary 









The chart above shows the possible value for each bit if the bit is turned on. If the bit is turned off the value is 0 (zero).
We use the chart above by placing the value of an octet in the lefttopcorner space and traversing the values in the decimal row, subtracting it from the value of the octet and them subtracting the remainder from the next bit. If a bit can be subtracted and leave a value greater than or equal to zero (except for 0 ? 0) we assign a value of 1 (one) to the bit otherwise we give the bit a 0 value.
Let?s see how this works using the same IP address we used earlier:
First octet:
192 
8 
7 
6 
5 
4 
3 
2 
1 

Decimal 
128 
64 
32 
16 
8 
4 
2 
1 
Value 
Binary 
1 
1 
0 
0 
0 
0 
0 
0 
11000000 
Second octet:
Third octet:
168 
8 
7 
6 
5 
4 
3 
2 
1 

Decimal 
128 
64 
32 
16 
8 
4 
2 
1 
Value 
Binary 
1 
0 
1 
0 
1 
0 
0 
0 
10101000 
1 
8 
7 
6 
5 
4 
3 
2 
1 

Decimal 
128 
64 
32 
16 
8 
4 
2 
1 
Value 
Binary 
0 
0 
0 
0 
0 
0 
0 
1 
00000001 
Fourth octet
16 
8 
7 
6 
5 
4 
3 
2 
1 

Decimal 
128 
64 
32 
16 
8 
4 
2 
1 
Value 
Binary 
0 
0 
0 
1 
0 
0 
0 
0 
00010000 
Now let?s look at the math.
Octet one = 192.
192 ? 128 leaves a remainder of 64 so the bit value under 128 is turned on (given the value of 1).
64 ? 64 leaves a remainder of 0 so the bit value under 64 is turned on (given the value of 1).
All the remaining bits are set to off (zero).
The first octet is 11000000.
Octet two = 168.
168 ? 128 leaves a remainder of 40 so the bit value under 128 is turned on (given the value of 1).
64 ? 40 would be less than zero so the bit value under 64 is turned off (given the value of 0).
40 32 leaves a remainder of 8 so the bit value under 32 is turned on (given the value of 1).
8 ? 16 would be less than zero so the bit value under 16 is turned off (given the value of 0).
8 ? 8 leaves a remainder of 0 so the bit value under 32 is turned on (given the value of 1).
All the remaining bits are set to off (zero).
The second octet is 10101000.
Octet three = 1.
The only bit that can be successfully subtracted is bit number one. Bit number 1 gets a value of 1 and all the other bits are turned off (given a value of 0).
The third octet is 00000001.
Octet four = 16.
Bits 8, 7 and 6 cannot be subtracted from 16 so they are turned off (given the value of 0).
16 can be subtracted from 16 so it is turned on (given the value of 1).
All the remaining bits are set to off (zero).
The fourth octet is 00010000.
Now we will concatenate the values of each octet to get the full binary representation of 192.168.1.16:
11000000101010000000000100010000.
For ease of reading we can add a period to separate each of the octets: 11000000.10101000.00000001.00010000.
You can take a 32 bit binary value and reverse the above process to convert back into an IP address and then convert the IP address to its decimal value equivalent.
I suggest you get in the habit of representing the binary equivalent of an IP address using the full 32bit value. This will make it much easier to understand our next lesson: Determining the Network and Broadcast Address Using an IP Address and Mask.
But before you get to the next lesson try converting the IP Addresses in the practice exam below to decimal and binary.
Practice Exam:
Convert the following IP Addresses to decimal and binary:
216.55.192.17
63.14.9.2
87.1.33.219
41.4.4.6
202.251.5.219
192.168.0.245
10.10.1.15
Decimal Conversion:
$octet1 x (256^3) = $decimal1
$octet2 x (256^2) = $decimal2
$octet3 x (256) = $decimal3
$octet4 = $decimal4
$decimal1 + $decimal2 + $decimal3 + $decimal4 = $decimal_equivalent
Binary Conversion:
First octet:

8 
7 
6 
5 
4 
3 
2 
1 

Decimal 
128 
64 
32 
16 
8 
4 
2 
1 
Value 
Binary 









Second octet:

8 
7 
6 
5 
4 
3 
2 
1 

Decimal 
128 
64 
32 
16 
8 
4 
2 
1 
Value 
Binary 









Third octet:

8 
7 
6 
5 
4 
3 
2 
1 

Decimal 
128 
64 
32 
16 
8 
4 
2 
1 
Value 
Binary 









Fourth octet:

8 
7 
6 
5 
4 
3 
2 
1 

Decimal 
128 
64 
32 
16 
8 
4 
2 
1 
Value 
Binary 








