# Convert Decimal IP address in Binary and Binary in Decimal

This tutorial explains how to convert a decimal IP address in binary IP address and a binary IP address in a decimal IP address step by step with examples. Learn the easiest method to convert a decimal IP address and subnet mask in binary IP address and subnet mask respectively.

An IP address and a subnet mask both collectively provide a numeric identity to an interface. Both addresses are always used together. Without subnet mask, an IP address is an ambiguous address and without IP address a subnet mask is just a number.

Both addresses are 32 bits in length. These bits are divided in four parts. Each part is known as octet and contains 8 bits. Octets are separated by periods and written in a sequence.

Two popular notations are used for writing these addresses, binary and decimal.

In binary notation, all four octets are written in binary format.

Examples of IP address in binary notation are following: -

00001010.00001010.00001010.00001010 10101100.10101000.00000001.00000001 11000000.10101000.00000001.00000001

Examples of subnet mask in binary notation are following: -

11111111.00000000.00000000.00000000 11111111.11111111.00000000.00000000 11111111.11111111.11111111.00000000

In decimal notation, all four octets are written in decimal format. A decimal equivalent value of the bits is used in each octet.

Examples of IP address in decimal notation are following: -

10.10.10.10 172.168.1.1 192.168.1.1

Examples of subnet mask in decimal notation are following: -

255.0.0.0 255.255.0.0 255.255.255.0

In real life you rarely need to covert an IP address and subnet mask from decimal to binary format and vice versa. But if you are preparing for any Cisco exam, I highly recommend you to learn this conversion. Nearly all Cisco exams include questions about IP addresses. Learning this conversion will help you in solving IP addressing related questions more effectively.

This tutorial is the third part of the article “Subnetting explained with examples”. Other parts of this tutorial are available here.

Network Addressing basic concepts explained

This tutorial is the first part of the article. It explains what IP address is and how IP address works in computer network including IP classes, subnet mask, private IP addresses, public IP addresses, reserved IP addresses, network address and broadcast address in detail.

Basic subnetting in computer network

This tutorial is the second part of the article. It explains basic concepts of Subnetting such as what Subnetting is and why it is done including the advantages and disadvantages of Subnetting.

Subnetting explained with examples

This tutorial is the fourth part of the article. It explains methods and techniques of Subnetting which you need in learning and performing Subnetting in correct and easy way.

### Understanding base value and position

Except the base value, binary system works exactly same as decimal system works. Base value is the digits which are used to build the numbers in both systems. In binary system, two digits (0 and 1) are used to build the numbers while in decimal system, ten digits (0,1,2,3,4,5,6,7,8,9) are used to build the numbers. In order to convert a number from binary to decimal and vice versa, we have to change the base value. Once base value is changed, resulting number can be written in new system.

Since IP address and subnet mask both are built from 32 bits and these bits are divided in 4 octets, in order to convert these addresses in binary from decimal and vice versa, we only need to understand the numbers which can be built from an octet or 8 bits.

- A bit can be either on or off.
- In binary system
**on**bit is written as**1**and**off**bit is written as**0**in number. - In decimal system if bit is on, its position value is added in number and if bit is off, its position value is skipped in number.

Following table lists the position value of each bit in an octet.

Bit position | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |

Position value | 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |

- Regardless which system we use to write the octet, it always contains all 8 bits. Bits are always written from left to right.
- A number in which all 8 bits are
**off**is written as**00000000**in binary system. Same number is written as**0**(0+0+0+0+0+0+0+0) in decimal system. - A number in which all 8 bits are
**on**is written as**11111111**in binary system. Same number is written as**255**(128+64+32+16+8+4+2+1) in decimal system.

## Converting decimal number in binary number

To convert a decimal number in binary number, follow these steps: -

- Compare the position value of first bit with given number. If given number is greater than the position value, write
**0**in rough area of your worksheet. If given number is less than or equal to the position value, write the position value. - Add the position value of second bit in whatever you written in first step and compare it with the position value of second bit. If sum is greater than the position value, skip the position value. If sum is less than or equal to the position value, add position value in sum.
- Repeat this process until all 8 bits are compared. If sum becomes equal at any bit, write all reaming bits as
**0**.

Operation | In Decimal | In Binary |

Add | Use position value | Set bit to 1 |

Skip | Skip position value | Set bit to 0 |

Let’s take an example. Convert a decimal number 117 in binary.

- Given decimal number is
**117** - Calculation direction is
**Left to Right**

Bit position | position value | Comparison | Operation | In decimal | In binary |

1 | 128 | 128 is greater than 117 | Skip | 0 | 0 |

2 | 64 | 0+64 = 64 is less than 117 | Add | 64 | 1 |

3 | 32 | 0+64+32 = 96 is less than 117 | Add | 32 | 1 |

4 | 16 | 0+64+32+16 = 112 is less than 117 | Add | 16 | 1 |

5 | 8 | 0+64+32+16+8 = 120 is greater than 117 | Skip | 0 | 0 |

6 | 4 | 0+64+32+16+0+4 = 116 is less than 117 | Add | 4 | 1 |

7 | 2 | 0+64+32+16+0+4+2 = 118 is greater than 117 | Skip | 0 | 0 |

8 | 1 | 0+64+32+16+0+4+0+1 = 117 is equivalent to 117 | Add | 1 | 1 |

Once above comparison is done in rough paper: -

- To write the given number in decimal format, sum all the values of decimal field and write the result. In this example, it would be 0+64+32+16+0+4+0+1 =
**117**. - To write the given number in binary format, write all the values of binary field from left to right. In this example, it would be
**11110101**.

## Converting binary number in decimal number

To convert a binary number in decimal number, sum the values of all on bits. Let’s take an example. Convert a binary number 10101010 in decimal number.

- Given binary number is
**10101010** - Calculation direction is
**Left to Right**

Bit position | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |

position value | 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |

In binary | 1 | 0 | 1 | 0 | 1 | 0 | 1 | 0 |

In decimal | 128 | 0 | 32 | 0 | 8 | 0 | 2 | 0 |

Decimal value of binary number **10101010** is 128+0+32+0+8+0+2+0 = **170**.

###### Practice for you

- Pick any number from 0 - 255 and convert it in binary.
- Pick any combination from 00000000 - 11111111 and convert it in decimal.

### Converting an IP address and subnet mask

As we know IP address and subnet mask both are built from 4 individual octets separated by periods. We can use above methods to convert all octets individually. Once all four octets are converted, we can merge them again separating by periods.

That’s all for this part. In next part we will learn how to use this conversion in IP Subnetting. If you like this tutorial, please don’t forget to share it through your favorite social network.

Created By ComputerNetworkingNotes Published On 2018-07-04 16:24:14 Last Updated 2018-07-04 16:24:14