IPv4 guide
How to convert an IP address to binary and decimal formats
IP addresses identify devices on a network. An address contains a network part and a host part: the network part identifies the network, while the host part identifies a device or interface within it.
IPv4 addresses contain four decimal octets separated by dots, such as 192.168.1.1. IPv6 addresses are longer and use colon-separated hexadecimal groups, but this guide focuses on IPv4.
Step 1: understand the IPv4 format
An IPv4 address is a 32-bit value split into four 8-bit octets. Each octet is written as a decimal number from 0 through 255.
Step 2: convert each decimal octet to binary
Convert each octet separately, then add leading zeroes until every result is eight bits long. For 192.168.1.1:
192 = 11000000
168 = 10101000
1 = 00000001
1 = 00000001
Step 3: combine the four octets
Keep the dots between octets so the 32-bit result remains easy to read:
11000000.10101000.00000001.00000001
Step 4: convert binary octets back to decimal
For each 8-bit octet, add the place values whose bits are 1. The place values from left to right are 128, 64, 32, 16, 8, 4, 2, 1.
| Binary octet | Calculation | Decimal |
|---|---|---|
11000000 | 128 + 64 | 192 |
10101000 | 128 + 32 + 8 | 168 |
00000001 | 1 | 1 |
Writing those decimal octets with dots gives 192.168.1.1.
More worked examples
10.0.0.1
00001010.00000000.00000000.00000001
172.16.0.1
10101100.00010000.00000000.00000001
Exercises
- Convert
192.168.1.10to binary. - Convert
00001010.00001010.00001010.00001010to dotted decimal. - Convert
172.16.0.1to binary. - Convert
11000000.10101000.00000000.11111111to dotted decimal. - Convert
172.31.255.255to binary. - Convert
11111111.11111111.11111111.00000000to dotted decimal. - Convert
198.51.100.0to binary. - Convert
11110000.00000000.00000000.00000000to dotted decimal.
