Binary representations of IP addresses
4 min read
In the previous article, we discussed how private IP addresses and NAT saved us from the threat of running out of IPv4 addresses.
In this article, we will see how IP addresses are represented in the binary form i.e how our computers see IP addresses. We will also learn how to convert a binary IP address to a decimal form and vice versa.
Read my previous article.
Binary vs Decimal numbers
First of all, let's discuss what even is a binary number and a decimal number. Then we are gonna see how we can convert binary to decimal and vice versa.
Binary numbers are a way of representing numbers using only two digits: 0 and 1. These digits are known as bits. In a binary number, each digit is a power of 2. Binary numbers are used in computing to represent data and perform operations because computers are designed to work with and manipulate bits.
Decimal numbers are numbers that use a base-10 system. In the decimal system, there are ten possible digits for each place value: 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9. The value of a decimal number is determined by the sum of each digit in the number multiplied by a power of 10. Decimal numbers are used in computers because they are easy for humans to understand and work with. They are also very useful for making calculations and storing information.
The binary form of IP addresses
This is the binary representation of the IP address 192.168.1.21 which is in decimal form.
Now you may be wondering how 192.168.1.21 turned out to be in the form of 0's and 1's? We will come to that later but first, let's discuss this IP address in binary form!
Now first, what I want you to do is count how many digits are here.
32 right? Or we could also say 32 bits. This is actually the size of an IP address in bits. Thus we call this a 32 bits IP address.
You may be thinking what do these numbers even mean? Well, this is what binary is and this is all your computer cares about i.e 1's & 0's. But it's more than just like 1's & 0's, it's what the 1's & 0's are communicating to the computer. 1 indicates ON and 0 indicates OFF. By doing this we are communicating with the computer. This may look weird but this is the language to communicate with computers and humans can't understand.
Binary to decimal conversion
Knowing to convert a binary number to a decimal number and a decimal number to a binary number is a very important skill in subnetting.
We are going to convert a binary number i.e 11000000.10101000.00000001.00010101 to a decimal number with the help of the powers of the 2 chart.
Step 1: We are going to write the powers of 2 chart from left to right
The chart above is the powers of the 2 chart. With this, we can convert any binary number to a decimal number and vice versa. Let's see how we can do that.
Step 2: We are going to write the digits of the first octet of the binary number below the powers of the 2 chart from left to right
We arranged the digits of the first octet of the binary number below the chart from left to right.
Step 3: We are going add the numbers from the powers of the 2 chart below which we see '1' because 1 = ON.
After adding the numbers we get the first digit of our Decimal number i.e 192. Similarly, after converting the rest 3 octets from binary to decimal we get 192.168.1.21 i.e the IP address in the decimal format.
Thus we have successfully converted an IP address from Binary to Decimal format.
Decimal to binary conversion
We learned how to convert a binary number to a decimal number. Now we will see how to convert a decimal number to a binary number. Let's take 172.16.34.3 for example. We will convert this IP address in decimal format to a binary number.
Step 1: Make the powers of 2 chart.
Step 2: Look for the numbers which when added give us the number 172 and write '1' below those numbers. Write '0' below the left-out numbers.
This is how we get the first octet of our IP address in binary format. Similarly, after converting the rest 3 octets from decimal to binary we get 10101100.00010000.00100010.00000011 i.e the IP address in binary format.
In this article, we discussed the binary form and decimal form of an IP address. We also learned how we can convert one form to the other. Learning this was essential because these are the basics of subnetting.
In the next article, we will discuss about the Subnet Mask in an IP address. Till then, thanks for reading.
Connect with me
Did you find this article valuable?
Support Ayaan Bordoloi by becoming a sponsor. Any amount is appreciated!