# Binary-to-decimal conversion

## Binary to decimal conversion is explained in this tip on how a network device uses its IP address, subnet mask and default gateway information.

To be a network engineer, you need to understand binary so that you can understand how a network device uses its...

IP address, subnet mask, and default gateway information. You also need to be able to convert from binary to decimal and from decimal to binary.

What is binary?

Binary is a numbering system that uses only the digits 1 and 0. We are accustomed to using the decimal number system, which uses the digits 0 through 9.

Binary is the numbering system that network devices use to process all data. Without binary, computers and networks would not function. All data sent across a network is in binary.

Just like we use the decimal numbering system (numbers 0 through 9) for all counting, money, and financial transactions, computers use binary for storage of all data, all data transmissions, and all numerical calculations. You can think of this as a language. For example, all people in Russia use Russian for all communication. If someone in Russia talked to someone in the United States, they would probably talk in English so that we could understand and communicate. That person would be bilingual because they understand two languages. In that sense, you could compare the computer to them because the computer understands two numbering systems, binary and decimal. Humans don't want to have to think or do calculations in binary. We want to convert those binary numbers to decimal. Converting from binary to decimal is not difficult. The numbers 0 and 1 in binary are converted to 0 and 1 in decimal. After that, it gets a little more complicated.

Here is an example of counting from zero to ten using binary:

 Decimal Binary 0 0 1 1 2 10 3 11 4 100 5 101 6 110 7 111 8 1000 9 1001 10 1010

All binary to decimal or decimal to binary conversions use this chart:

 27 26 25 24 23 22 21 20 128 64 32 16 8 4 2 1

Let's discuss how to use this chart. First, always start by looking at the chart from right to left, not from left to right. Second, all the numbers on the chart stay where they are -- you don't change these. These numbers are used to tell you the values of the binary digits you will enter in the blanks.

Finally, the top line of 2x numbers tells you what each column represents. The column on the far right is worth 20. The second line, with the decimal numbers, tells you what the answer is to the 20 line. So, if you look at the column on the far right, second line, it tells you that 20 is equal to 1 IF there is a 1 in the blank below it. If you had a one in the fourth column from the right, 23, you would have a value of 8 turned ON. Anywhere that you do not have a 1 in the bottom line, you will fill in with a zero. Think of each of these columns being able to be turned ON and OFF by using a 1 or a 0, respectively.

When you are done filling in your 1's and 0's on the bottom line of the chart, you can add all the values that you turned ON, in decimal, from left to right (using the second line of the chart). Thus, if you had put a 1 in the 23 column (8) and a 1 in the 20 column (1), you would add 8 + 1 = 9. That 9 is represented by 1001.

These numbers are calculated using this table:

 27 26 25 24 23 22 21 20 128 64 32 16 8 4 2 1 = 9 0 0 0 0 1 0 0 1 = 1001

Let's look at another example... If you look at the number 3, it was calculated by having a 1 in the 20 place and a 2 in the 21 place (starting on the right-hand side of the table). If you add the 1 that you get from the 20 place and the 2 that you get from the 21 place, you get 3. In other words, 1 + 2 = 3.

Let's look at another one. The 1000 in binary represents 8 in decimal because you have a 1 in the 23 place and that gives you 8. You have 0's in all the other places.

The three critical pieces of information that you, the network administrator, provide or a DHCP server provides to network devices (computer, server, router, switch, etc.) are:

• Default Gateway

The network device immediately converts this information into binary. So, let's pretend that we are that network device and we are given the following information:

• Default Gateway = 1.1.1.254

The computer converts this information into binary and calculates the Network ID. Before we can calculate the Network ID, we first have to convert from decimal to binary.

Converting decimal to binary

Let's start with converting the IP address to binary. To convert 1.1.1.1 to binary, you take the octets (the numbers between the decimals) one at a time, like this:

1 decimal = 1 binary
1 decimal = 1 binary
1 decimal = 1 binary
1 decimal = 1 binary

An IP address is 32 bits in binary, so each octet is 8 bits in binary. Because of this, we need to pad the other bits as 0's. That means that 1.1.1.1 in decimal equals the following number in binary:
00000001 00000001 00000001 00000001

That was easy! To convert the subnet mask of 255.255.255.0, take each octet one at a time, using the table:

 27 26 25 24 23 22 21 20 128 64 32 16 8 4 2 1

Here is what I get:
255 = 11111111

To do this, I looked at the bottom row of numbers that each binary space represents. I started with 27, which equals 128. So, how many 128's are in 255? The answer is 1. So I write:
255 – 128 = 127

Now, how many 64's (the next binary space) are in 127? The answer is 1, so I write: 127 – 64 = 63

And so on, like this:
63 – 32 = 31
31 – 16 = 15
15 – 8 = 7
7 – 4 = 3
3 – 2 = 1
1 – 1 = 0

So, I used all 8 binary spaces to calculate the 255 in decimal, to be 11111111 in binary. The last octet is a 0, so 0 in binary is 0 but we write 00000000. As you get more experience you will already know that eight 1's in binary equals 255 in decimal.

The total subnet mask in binary is:
11111111 11111111 11111111 00000000

00000001 00000001 00000001 00000001
11111111 11111111 11111111 00000000

Calculating the network ID

The network device on which you configured this IP addressing information must know what its network ID is. The network ID tells the device what its local network is. If the destination IP address for the network device with which this network device is trying to communicate is not on its local network, that traffic is sent to the default gateway. Thus, the default gateway is used only if the destination for the traffic your device is sending is not on your local network.

To calculate the network ID, start off with the IP address and subnet mask in binary, from above:

 IP Address 00000001 00000001 00000001 00000001 Subnet Mask 11111111 11111111 11111111 00000000

Perform a logical AND on these. A logical AND is a math function where you look at each row and calculate an answer based on the following rules:

• 0 and 0 = 0
• 0 and 1 = 0
• 1 and 1 = 1

In our case, this is the answer you get:

 IP Address 00000001 00000001 00000001 00000001 Subnet Mask 11111111 11111111 11111111 00000000 AND Network ID 00000001 00000001 00000001 00000000

Using the AND rules, I look at the first 0 in the IP address and the first 1 in the subnet mask. I see that, according to the rules, a 0 and a 1 = 0. That is how I calculated the first 0 in the network ID. To continue, I go from left to right, calculating each row.

Notice that the only difference between the IP address and network ID is in the last number of the last octet. Now, to get the Network ID in decimal, we convert this back. This is a simple example, so converting it back is easy. The 00000001 in binary is converted to 1 in decimal. In the last octet, the 00000000 is converted to 0. This makes our network ID:
1.1.1.0

So, when the network device wants to communicate with a host that has the IP address of 1.1.1.200, it compares this with its network ID and finds that this host is on the local network. The network device can then communicate directly with it because it is on the 1.1.1.0 network. If the network device wants to communicate with host 1.1.2.1, however, it finds that this is NOT on its local network (the 1.1.1.0 network) and it sends this traffic to the default gateway.

These examples are, of course, very simplified, since this topic can get very complex when you begin subnetting networks and using variable-length subnet masks.

Article summary

Here is what we have learned:

• Binary is a numbering system using only 1 and 0.
• Use the binary conversion chart to convert from binary to decimal and back.
• Your network device/computer calculates the Network ID using the IP address and subnet mask it is provided.
• To calculate the Network ID, the computer performs a math calculation called a "logical AND."
• A default gateway is not required for a device that will not communicate outside its local network.

David Davis (CCIE #9369, CWNA, MCSE, CISSP, Linux+, CEH) has been in the IT industry for 15 years. Currently, he manages a group of systems/network administrators for a privately owned retail company and authors IT-related material in his spare time. He has written over fifty articles, eight practice tests and three video courses and has co-authored one book. His website is at www.happyrouter.com.

This was last published in May 2006

## Content

Find more PRO+ content and other member only offers, here.

#### Start the conversation

Send me notifications when other members comment.

## SearchSDN

• ### Virtual wire network transport mission could increase SDN usage

SDN's use as virtual wire to provide network transport could get the technology out of the data center to underlay SD-WAN better ...

• ### Viptela names former Cisco exec Akkiraju CEO amid SD-WAN market shift

Viptela, a startup in the SD-WAN market, taps former Cisco exec Praveen Akkiraju as its new CEO. Akkiraju's immediate goal for ...

• ### I2RS, Interface to the Routing System, remains viable SDN hybrid

One SDN blogger discusses I2RS, a hybrid model of SDN in the works, while another expert categorizes NFV and SDN vendors. Also, ...

## SearchEnterpriseWAN

• ### The best VPNs for enterprise use

This slideshow highlights the best VPNs used in enterprise wide-area networks (WANs) and offers principles for designing and ...

• ### Cloud-managed networking makes VPN a snap

Provisioning and deploying a WAN and VPN is an everyday function for engineers. But can you do that for an office 4,000 miles ...

• ### Three new takes on WAN optimization

Once considered new technology, WAN optimization is now widespread, and enterprises are including it in their networks from the ...

## SearchUnifiedCommunications

• ### Avaya bankruptcy filing targets restructuring for cloud, software

Avaya has filed for Chapter 11 bankruptcy protection as it focuses on restructuring its \$6 billion debt. Analysts anticipate a ...

• ### A hybrid deployment gives organizations UC flexibility

Two factors are driving the hybrid deployment of unified communications: infrastructure needs and business value. But enterprises...

• ### Zoom meetings jettison complex video infrastructure

With cloud-based video meetings from Zoom Video Conferencing, businesses can host collaborative online meetings in the office and...

## SearchMobileComputing

• ### Citizen developers pull the rug out from under IT with RMAD tools

End users want mobile apps to help with basic job functions, but the cost and time it takes IT and developers to deliver those ...

• ### Advanced Citrix XenMobile MDM comes to Intune, but who's buying?

Citrix XenMobile mobile device management policies, features and mobile apps will soon be available to Microsoft shops as an ...

• ### Look to the future of the wearable technology trend

The enterprise potential for wearable technology is high, with accurate health trackers and 3D graphics becoming more common. ...

## SearchDataCenter

• ### HPE-SimpliVity deal raises support, price and development questions

With HPE's buy of No. 2 SimpliVity -- the first big deal in the HCI space -- IT pros see a more robust offering, but also higher ...

• ### Converged infrastructure drop-off doesn't mean data center death

Traditional converged infrastructure has been supplanted by hyper-converged infrastructure and cloud computing, but it remains a ...

• ### New options to evolve your data backup and recovery plan

The server backup market first evolved to protect VMs, but now it's undergoing another transformation. Find out how it's evolved ...

## SearchITChannel

• ### Shipments of 25/100 GbE switches surpassing 10/40 GbE

Research finds shipments of 25 GbE and 100 GbE switches are outpacing 10/40 GbE hardware, as companies find more value in the ...

• ### CTOs offer up enterprise storage predictions for 2017

CTOs share enterprise storage predictions for 2017. Cloud, server-based storage, HCI, and growing use of containers and analytics...

• ### Avaya files for chapter 11 bankruptcy

Networking supplier has filed voluntary petitions under chapter 11 of the US bankruptcy code.

Close