- Use mathematics to convert an IP address to binary
- Use a simple command-line application to convert an IP address to binary from decimal
Use mathematics to convert an IP address to binary
There is an advantageous way to convert an IP address from decimal to binary using mathematics. This is not too hard after all.
- Write down the decimal number of the first octet of the IP address.
- Convert the decimal number to binary by dividing it by 2 repeatedly and writing down the remainder (0 or 1) each time, starting from the bottom.
- Continue this process with the remaining three octets of the IP address.
For example, we are converting the IP address 192.168.0.1, which is /24 to binary.
- Write down the decimal number of the first octet: 192
- Convert 192 to binary:192 / 2 = 96,
remainder 096 / 2 = 48,
remainder 048 / 2 = 24,
remainder 024 / 2 = 12,
remainder 012 / 2 = 6,
remainder 06 / 2 = 3,
remainder 03 / 2 = 1,
remainder 11 / 2 = 0,
remainder 1
So, the binary representation of 192 is 11000000. - Repeat this process for the remaining octets:
168 -> 101010000 -> 000000001 -> 00000001.
Therefore, the binary representation of the IP address 192.168.0.1 is 11000000.10101000.00000000.00000001.
This is an easy way to convert an IP address to binary using simple math.
Use a simple command-line application to convert an IP address to binary from decimal
There is also a nice command-line application to convert an IP address to binary. The ipcalc app is very useful for working with IP addresses. Below is an example, of converting a /24 IP address to binary.
┌──(john㉿DESKTOP-PF01IEE)-[~] └─$ ipcalc 192.168.0.1/24 Address: 192.168.0.1 11000000.10101000.00000000. 00000001 Netmask: 255.255.255.0 = 24 11111111.11111111.11111111. 00000000 Wildcard: 0.0.0.255 00000000.00000000.00000000. 11111111 => Network: 192.168.0.0/24 11000000.10101000.00000000. 00000000 HostMin: 192.168.0.1 11000000.10101000.00000000. 00000001 HostMax: 192.168.0.254 11000000.10101000.00000000. 11111110 Broadcast: 192.168.0.255 11000000.10101000.00000000. 11111111 Hosts/Net: 254 Class C, Private Internet |
Another way is to use sipcalc. This is a very good application for calculating networks.
This shows that a network using these IP addresses would have 28 possible addresses.
┌──(john㉿DESKTOP-PF01IEE)-[~] └─$ sipcalc -a 10.2.0.1/28 -[ipv4 : 10.2.0.1/28] - 0 [Classful] Host address - 10.2.0.1 Host address (decimal) - 167903233 Host address (hex) - A020001 Network address - 10.0.0.0 Network class - A Network mask - 255.0.0.0 Network mask (hex) - FF000000 Broadcast address - 10.255.255.255 [CIDR] Host address - 10.2.0.1 Host address (decimal) - 167903233 Host address (hex) - A020001 Network address - 10.2.0.0 Network mask - 255.255.255.240 Network mask (bits) - 28 Network mask (hex) - FFFFFFF0 Broadcast address - 10.2.0.15 Cisco wildcard - 0.0.0.15 Addresses in network - 16 Network range - 10.2.0.0 - 10.2.0.15 Usable range - 10.2.0.1 - 10.2.0.14 [Classful bitmaps] Network address - 00001010.00000000.00000000.00000000 Network mask - 11111111.00000000.00000000.00000000 [CIDR bitmaps] Host address - 00001010.00000010.00000000.00000001 Network address - 00001010.00000010.00000000.00000000 Network mask - 11111111.11111111.11111111.11110000 Broadcast address - 00001010.00000010.00000000.00001111 Cisco wildcard - 00000000.00000000.00000000.00001111 Network range - 00001010.00000010.00000000.00000000 - 00001010.00000010.00000000.00001111 Usable range - 00001010.00000010.00000000.00000001 - 00001010.00000010.00000000.00001110 [Networks] Network - 10.2.0.0 - 10.2.0.15 (current) Network - 10.2.0.16 - 10.2.0.31 Network - 10.2.0.32 - 10.2.0.47 Network - 10.2.0.48 - 10.2.0.63 Network - 10.2.0.64 - 10.2.0.79 Network - 10.2.0.80 - 10.2.0.95 Network - 10.2.0.96 - 10.2.0.111 Network - 10.2.0.112 - 10.2.0.127 Network - 10.2.0.128 - 10.2.0.143 Network - 10.2.0.144 - 10.2.0.159 Network - 10.2.0.160 - 10.2.0.175 Network - 10.2.0.176 - 10.2.0.191 Network - 10.2.0.192 - 10.2.0.207 Network - 10.2.0.208 - 10.2.0.223 Network - 10.2.0.224 - 10.2.0.239 Network - 10.2.0.240 - 10.2.0.255 |
This is a most useful tool to calculate a subnet easily. Subnets can be very challenging, and this takes the pain out of this for everyone.