Inside network devices, digital logic is applied to their interpretation of the addresses. When creating an IPv4 packet, the destination network address must be extracted from the destination address. This is done by a logic called ANDing. ANDing is the basic binary operation to determine network address. There is two other process that is also used in data networking but not used for determining IP address. The other two are OR and NOT operation. The IPv4 address is logically ANDed with its subnet mask to determine the associated network address. When ANDing between the address and the subnet mask performed, the result gives the network address.
A Logic AND Gate is a type of digital logic gate that has an output which is usually at logic level “0” and only goes “HIGH” to a logic level “1” when ALL of its inputs are at logic level “1”
The output state of a “Logic AND Gate” return “LOW” when any of its inputs are at a logic level “0”. In other words for a logic AND gate, any LOW input will give a LOW output.
The logic expression given for a digital logic AND gate is that for Logical Multiplication which denoted by a single dot or full stop symbol, ( . ) giving us the Boolean expression of A.B = X
Logical AND is the operation of two bits that gives the following result.
0 AND 0 = 0
0 AND 1 = 0
1 AND 0 = 0
1 AND 1 = 1
So Anything ANDed with a 0 produces a 0. We can use these characteristics of ANDing with the subnet mask to “mask” the host bits of an IPv4 address. Each bit of the address is ANDed with the parallel bit to the subnet mask. As we learn in previous lessons that all bits of the subnet mask that represent host bits are 0s, the host portion of the resultant network become all 0s. Remember that all 0 in the host portion of IPv4 address mean that this is the network address. As we know that all bits of subnet mask in network portion are all 1s. when each of these 1s ANDed with a parallel bit of the address, the resulting bits are identical to the original address bits.
So to identify the network address of an IPv4 host, the IPv4 address is logically ANDed, bit by bit, with the subnet mask. ANDing between the address and the subnet mask produce the network address.
Example 1: Find out what the network ID for the following IP address.
IP address: 192.168.100.150
IP subnet mask: 255.255.255.0
The binary equivalent for IP address 220.127.116.11:
- 192 binary is 11000000
- 168 binary is 10101000
- 100 binary is 01100100
- 50 binary is 00110010
So the binary for this IP address is: 11000000.10101000.01100100.00110010
Now look at the binary equivalent for the subnet mask 255.255.255.0:
- 255 binary is 11111111
- 255 binary is 11111111
- 240 binary is 11111111
- 0 binary is 00000000
So the binary for the subnet mask is 11111111. 11111111. 11111111. 00000000
Now subtract the binary IP address from the binary subnet mask
And then convert it to decimal.
Binary IP Address: 11000000.10101000.01100100.00110010
Binary subnet mask: 11111111. 11111111. 11111111.00000000
Binary Result 11000000. 10101000.01100100.00000000
Decimal result: 192. 168. 100. 0
So the network ID for this IP/subnet is 192.168.100.0. Let’s check the network ID for 172.16.31.240 IP address which subnet mask is 255.255.248.0
IP address: 172.16.31.240
IP subnet mask: 255.255.248.0
The binary for this IP address is: 10101100.00010000.00011111.11110000 and the binary equivalent for the subnet mask 255.255.248.0
The binary for the subnet mask is 11111111. 11111111. 11110000. 00000000
now subtract binary subnet mask from binary IP address.
Binary IP Address: 10101100.00010000.00011111.11110000
Binary subnet mask: 11111111. 11111111. 11110000.00000000
Binary Result 10101100.00010000.00010000.00000000
Decimal result: 172. 16. 16. 0