Binary Math – CompTIA Network+ N10-009 – 1.7

If you’re calculating IP subnets, it will be useful to understand the basics of binary math. In this video, you’ll learn how to convert between decimal and binary IP addresses.


In the next part of this course, we’re going to talk a lot about IP subnetting. And a big part of subnetting is the ability to convert between decimal and binary. So I thought it would be useful in this video if we step through the fundamentals of performing binary calculations.

Binary, of course, is a type of numbering that uses two different numbers, either a 0 or a 1. This means that there are only two possible options when doing mathematics. In binary, the answer is either going to include a 0, or it’s going to include a 1.

Each one of these 0’s or 1’s is referred to as a bit. And when we combine eight of these bits together, we have a byte. Occasionally, you will see a byte referred to as an octet to be sure that everyone understands that this is an 8-bit byte.

In this video, we’re going to perform a lot of calculations between binary and decimal. So what we need to create is a conversion chart to convert between binary and decimal. We’ll create this chart by starting on the right side. And we’ll simply put the number 1. Then we’re going to double that number and put it to the left. So doubling 1 makes the number 2. If we double the number 2, we have the number 4. 4 times 2 is 8. 8 times 2 is 16. 16 times 2 is 32, and so on.

This is the conversion chart that we will use for almost all of our decimal-to-binary conversions. We created this chart with eight individual places. But you could keep moving to the left with this chart and go past 128. We’ll double it to 256. We’ll double that to 512, and so on. You can keep continuing this process so that if you have a very large binary number, you can still perform the same type of conversion back to decimal.

Let’s now use this chart to answer this question. What is the binary 00000010 in decimal? First, let’s write down this value in decimal. So it’s 00000010. And of course, we want to know what the decimal equivalent is of that binary value.

We’ll then layer on top of this our conversion chart. So of course, we start on the right side with a 1, then 2, 4, 8, 16, 32, 64, and 128. Now we have everything we need to perform this binary calculation. In each of these places where we have a binary 0, we’re going to bring that 0 down to the bottom line. In every place where we have a binary of 1, we’re going to take the number just above that and bring it down onto the bottom line.

We’re then going to add all of these numbers together on the bottom line. So 0 plus 0 plus 0 plus 0 plus 0 plus 0 plus 2 plus 0 equals 2 in decimal. So the answer to this question of converting binary 00000010 is the same as 2 decimal.

Let’s do another one. What is the binary 10000010 in decimal? We will write down our binary value. And then we’ll layer on top of that our conversion chart. Every place there is a 0, we’re going to pull that down and put a 0. And every place there is a 1, we’re going to pull down the number just above that 1.

And you can see we only have two binary 1’s in this number. And that’s associated with the 2 and associated with the 128. So we’ll bring down the 128. We’ll bring down the 2. We add those together. And we’ve got 130 in decimal. So the binary value 10000010 is the same as 130 in decimal.

And finally, let’s do one more binary-to-decimal conversion. This binary value is 11111111. We’ll bring down that binary value. And we’ll layer on top of that our conversion chart. And because each one of these spaces has a 1, we’re going to bring down all of the numbers of our conversion. And if we were to count 128 plus 64 plus 32 plus 16 plus 8 plus 4 plus 2 plus 1, you would have the value of 255 decimal. So the conversion of 11111111 in binary is the same as 255 in decimal.

Now let’s do the same conversion but in reverse. Let’s take a decimal number and convert it to binary. This question asks, what is the decimal 154 in binary? It’s the same process. We’re going to bring down our binary number. But of course, we don’t know what that binary number is yet. So we’ll put some place marks here. And then we’ll layer on top of this our conversion chart.

Now we need to determine which one of these binary values will be a 0 and which one will be a 1 to make up 154 decimal. And there is only one combination of 0’s and 1’s in this chart that would equal that decimal value. We’ll start on the right side, where we have our 128 column. And we’ll ask ourself, is 128 less than or equal to 154? This is obviously less than 154. So we’ll put a 1 in that column. And we’ll bring down the 128.

Now let’s look at our next column of 64. And we’ll combine that next column with the numbers that we’ve currently brought down previously– in this case, the number 128. So 128 plus 64 is 192. And we have to ask ourself, is 192 less than or equal to 154? In this case, 192 is more than 154. So the answer is no. And we’ll put a 0 in that column.

Now we move to the next column, which is our 32. We’ll add 32 plus anything that we brought down. That would be 128 plus 32, which equals 160. Is 160 less than or equal to 154? It is not. So we’ll bring down a 0 in that column. We’ll continue with this process by looking at the fourth column, which is 16. We’ll add that to anything that we brought down.

So 128 plus 16 is 144. Is 144 less than or equal to 154? It is. So we’ll put a 1 in that column and bring down the 16. Our next column is the 8. So we’ll add 8 to anything that we’ve previously brought down. So 128 plus 16 plus 8 is 152. Is 152 less than or equal to 154? It is. So we’ll put a 1 in that column and bring down the number 8.

Our next column is the number 4. We will add 4 to everything that we brought down into that bottom row. So that all adds up to 156. And is 156 less than or equal to 154? It is not. So we’ll put a 0 in the 4 column.

The next column is the number 2. We’ll add the number 2 to everything that we brought down so far. And if we add all of those up, it would be 154. Is 154 less than or equal to 154? It’s obviously equal to 154. So we’ll put a 1 in that column and bring down the number 2.

And obviously, we’ve hit the number 154. So we know that the number 1 on the last column will not be added to this final value. And if we add up everything in that last row, we see it does equal 154. And now all we have to do is look at the middle row to determine what the binary value of this is. And it would be 10011010. If we look at 154 decimal, we know that that is exactly the same as 10011010 in binary.

With these eight individual bits, we can convert any number between 0 and 255. So take any number you would like. Put it into this particular format. And see if you can perform the conversion between binary and decimal.

As you’re increasing the number of bits in a binary value, you’re increasing the total possible number of decimal results. For example, if you have 2 bits, there are only four possible outcomes– 00, 01, 10, and 11. And if you were to perform that conversion between binary and decimal, that’s the same as 0, 1, 2, and 3.

If you have 3 bits, then you can have eight possible outcomes. If you use four individual bits, you have up to 16 different options. 5 bits moves you up to 32. Six would be 64. 7 bits is 128 possible options. And if you were to increase the number of bits into 9 bits, 10 bits, 11 bits, and so on, you would also increase the total decimal number.

You can see that this value is listed in this chart. And notice that I’ve also added the powers of 2 on top of this. This is effectively what we’ve been doing the whole time. 2 to the 0 power is 1. 2 to the first power is 2. 2 to the second power is 4. 2 to the third power is 8, and so on. So as we increase this powers of 2, we are also increasing the total decimal value.