Section 3.4: Determining the Network ID using the Logical AND
Operation
When an IP address is assigned to an interface, it is configured with the subnet mask. Although represented in a dotted decimal format, the router converts the IP address and the subnet mask into binary and performs a logical and
operation to find the network portion of the address, i.e., the network ID. To perform a logical and
, the IP address is written out in binary, with the subnet or Internet mask written beneath it in binary. Each binary digit of the address is then AND
ed with the corresponding binary digit of the mask. The and
operation has two rules: 1 and 1
is 1
; and 0 and 1
or 0
remains 0
. Essentially, the logical and
operation removes the host ID from the IP address, as illustrated in Figure 3.4.
IP address: | 140.12.26.128 |
IP subnet mask: | 255.255.240.0 |
IP address in binary: | 10001100.00001100.00011010.10000000 |
IP subnet mask in binary: | 11111111.11111111.11110000.00000000 |
The result of the logical AND in binary: |
10001100.00001100.00010000.00000000 |
The result of the logical AND in dotted decimal format: |
140.12.16.0 |
Figure 3.4: The Logical AND Operation
In the above example, the network to which the host 140.12.26.128 belongs has the network ID of 140.12.16.0. Once the network ID is determined, the router can perform a search on the routing table to see whether it can route to the remote network. Therefore, the correct mask is essential to ensure that traffic can be directed through the overall network.