Binary ANDing: multiplication to two binary numbers with examples

Binary ANDing -How To?
Andrey Volkov

Andrey Volkov

System, network administration + DBA. And a little programmer!)) See Author profile.

Binary ANDing is the process of performing multiplication to two binary numbers. In the decimal numbering system, ANDing is addition: 2 and 3 equals 5. In decimal, there are an infinite number of answers when ANDing two numbers together. However, in the binary numbering system, the AND function yields only two possible outcomes, based on four different combinations. These outcomes, or answers, can be displayed in what is known as a truth table:

0 and 0 = 0

1 and 0 = 0

0 and 1 = 0

1 and 1 = 1

You use ANDing most often when comparing an IP address to its subnet mask. The end result of ANDing these two numbers together is to yield the network number of that address.

Question 1

What is the network number of the IP address 192.168.100.115 if it has a subnet mask of 255.255.255.240?

Answer

Step 1. Convert both the IP address and the subnet mask to binary:

 

192.168.100.115 = 11000000.10101000.01100100.01110011

255.255.255.240 = 11111111.11111111.11111111.11110000

Step 2. Perform the AND operation to each pair of bits—1 bit from the address ANDed to the corresponding bit in the subnet mask. Refer to the truth table for the possible outcomes.

 

192.168.100.115 = 11000000.10101000.01100100.01110011

255.255.255.240 = 11111111.11111111.11111111.11110000

ANDed result    = 11000000.10101000.01100100.01110000

Step 3. Convert the answer back into decimal:

11000000.10101000.01100100.01110000 = 192.168.100.112

The IP address 192.168.100.115 belongs to the 192.168.100.112 network 
when a mask of 255.255.255.240 is used.

 

Question 2

What is the network number of the IP address 192.168.100.115 if it has a subnet mask of 255.255.255.192?

(Notice that the IP address is the same as in Question 1, but the subnet mask is different. What answer do you think you will get? The same one? Let’s find out!)

Answer

Step 1. Convert both the IP address and the subnet mask to binary:

 

192.168.100.115 = 11000000.10101000.01100100.01110011

255.255.255.192 = 11111111.11111111.11111111.11000000

Step 2. Perform the AND operation to each pair of bits—1 bit from the address ANDed to the corresponding bit in the subnet mask. Refer to the truth table for the possible outcomes.

 

192.168.100.115 = 11000000.10101000.01100100.01110011

255.255.255.192 = 11111111.11111111.11111111.11000000

ANDed result   = 11000000.10101000.01100100.01000000

Step 3. Convert the answer back into decimal:

11000000.10101000.01100100.01110000 = 192.168.100.64

The IP address 192.168.100.115 belongs to the 192.168.100.64 network

when a mask of 255.255.255.192 is used.

 

So Why AND?

Good question. The best answer is to save you time when working with IP addressing and subnetting. If you are given an IP address and its subnet, you can quickly find out what subnetwork the address belongs to. From here, you can determine what other addresses belong to the same subnet. Remember that if two addresses are in the same network or subnetwork, they are considered to be local to each other and can therefore communicate directly with each other. Addresses that are not in the same network or subnetwork are considered to be remote to each other and must therefore have a Layer 3 device (like a router or Layer 3 switch) between them to communicate.

Question 3

What is the broadcast address of the IP address 192.168.100.164 if it has a subnet mask of 255.255.255.248?

Answer

Step 1. Convert both the IP address and the subnet mask to binary:

192.168.100.164 = 11000000.10101000.01100100.10100100
255.255.255.248 = 11111111.11111111.11111111.11111000

Step 2. Perform the AND operation to each pair of bits—1 bit from the address ANDed to the corresponding bit in the subnet mask. Refer to the truth table for the possible outcomes:

192.168.100.164 = 11000000.10101000.01100100.10100100
255.255.255.248 = 11111111.11111111.11111111.11111000
ANDed result    = 11000000.10101000.01100100.10100000  = 192.168.100.160 (Subnetwork #)

Step 3. Separate the network bits from the host bits:

255.255.255.248 = /29. The first 29 bits are network/

subnetwork bits; therefore,

11000000.10101000.01100100.10100000.

The last 3 bits arehost bits.

Step 4. Change all host bits to 1. Remember that all 1s in the host portion are the broadcast number for that subnetwork.

11000000.10101000.01100100.10100111

Step 5. Convert this number to decimal to reveal your answer:

11000000.10101000.01100100.10100111 = 192.168.100.167
The broadcast address of 192.168.100.164 is 192.168.100.167
when the subnet mask is 255.255.255.248.

Shortcuts in Binary ANDing

Remember that I said ANDing is supposed to save you time when working with IP addressing and subnetting? Well, there are shortcuts when you AND two numbers together:

  • An octet of all 1s in the subnet mask results in the answer being the same octet as in the IP address.
  • An octet of all 0s in the subnet mask results in the answer being all 0s in that octet.

Question 4

To what network does 172.16.100.45 belong, if its subnet mask is 255.255.255.0?

Answer

172.16.100.0

Proof

Step 1. Convert both the IP address and the subnet mask to binary:

172.16.100.45 = 10101100.00010000.01100100.00101101
255.255.255.0 = 11111111.11111111.11111111.00000000

Step 2. Perform the AND operation to each pair of bits—1 bit from the address ANDed to the corresponding bit in the subnet mask. Refer to the truth table for the possible outcomes.

172.16.100.45 = 10101100.00010000.01100100.00101101255.255.255.0 = 11111111.11111111.11111111.00000000 
0101100.00010000.01100100.00000000                               = 172.16.100.0

Notice that the first three octets have the same pattern both before and after they were ANDed. Therefore, any octet ANDed to a subnet mask pattern of 255 is itself! Notice that the last octet is all 0s after ANDing. But according to the truth table, anything ANDed to a 0 is a 0. Therefore, any octet ANDed to a subnet mask pattern of 0 is 0! You should only have to convert those parts of an IP address and subnet mask to binary if the mask is not 255 or 0.

Question 5

To what network does 68.43.100.18 belong if its subnet mask is 255.255.255.0?

Answer

68.43.100.0 (There is no need to convert here. The mask is either 255s or 0s.)

Question 6

To what network does 131.186.227.43 belong if its subnet mask is 255.255.240.0?

Answer

Based on the two shortcut rules, the answer should be

131.186.???.0

So now you only need to convert one octet to binary for the ANDing process:

227          = 11100011

240          = 11110000

11100000 = 224

Therefore, the answer is 131.186.224.0.

 

Вас заинтересует / Intresting for you:

What are IPv4 addresses used f...
What are IPv4 addresses used f... 251 views Андрей Волков Sat, 13 Feb 2021, 18:42:13
Network, Node and Broadcast Ad...
Network, Node and Broadcast Ad... 306 views Андрей Волков Sun, 14 Feb 2021, 06:14:12
Subnetting a Class C Network U...
Subnetting a Class C Network U... 310 views Андрей Волков Sun, 14 Feb 2021, 07:48:28
IPv6 Address Types: unicast, m...
IPv6 Address Types: unicast, m... 671 views Андрей Волков Mon, 15 Feb 2021, 08:11:12