Simplified IP datagram routing algorithm with subnets
When subnetting is used, the algorithm required to find a route for an IP datagram is similar to the one for general routing, with the exception that the addresses that are compared are the result of a logical AND of the subnet mask and the IP address.
For example:
IP address: 9.67.32.18 00001001 01000011 00100000 00010010
<AND>
Subnet Mask: 255.255.255.240 11111111 11111111 11111111 11110000
Result of
Logical AND: 9.67.32.16 00001001 01000011 00100000 00010000
The subnet address is 9.67.32.16, and it is this value that is used to determine the route used.
Figure 1 shows the routing algorithm used with subnets.
Figure 1. Routing algorithm
with subnets![If the destination IP address ANDed with my subnet mask equals one of my IP addresses ANDed with their subnet mask, send the IP datagram on the local network. If not, send the IP datagram to gateway that is corresponding to the destination IP address ANDed with my subnet mask.](lbkl007.gif)
![If the destination IP address ANDed with my subnet mask equals one of my IP addresses ANDed with their subnet mask, send the IP datagram on the local network. If not, send the IP datagram to gateway that is corresponding to the destination IP address ANDed with my subnet mask.](lbkl007.gif)
Figure 2 shows how a subnet route is resolved.
Figure 2. Example of resolving
a subnet route![Diagram that shows how to resolve a subnet route. After the destination IP address 9.67.32.34 is ANDed with subnet mask 255.255.255.240, it becomes 9.67.32.32. This new IP address does not equal my IP address 9.67.32.16 and it is corresponding to the gateway 9.67.32.18, to which the IP datagram is finally sent.](lbkl1030.gif)
![Diagram that shows how to resolve a subnet route. After the destination IP address 9.67.32.34 is ANDed with subnet mask 255.255.255.240, it becomes 9.67.32.32. This new IP address does not equal my IP address 9.67.32.16 and it is corresponding to the gateway 9.67.32.18, to which the IP datagram is finally sent.](lbkl1030.gif)