IP Routing table - process by which entries are matched
When an IP packet arrives on a router, the destination address is compared to the entries in the routing table. The router goes through all of the routing entries in the routing table and attempts to match it to a particular entry. If there are multiple entries that the destination IP address matches, the following criteria are used:
- First, the more specific entry is matched. In other words, the entry with the smallest subnet mask is used. Put a different way, the entry with the longest prefix is matched.
- If the subnet mask is the same, then load balancing takes place.
In the event that there is no match, the default route or gateway of last resort is used if configured. Otherwise the packet is dropped.
Note that one would assume that the administrative distance (AD) also plays a role, and it does, but not in the choice of installed routes. The AD will be used to determine if a route will be installed in the routing table in the event that two identical routes, with identical prefix lengths, are learned from different sources. If this happens, the route with the lower AD will be installed. The other route will never be in the routing table, thus it is never an option for a packet coming into the router.
Links:
https://forum.networklessons.com/t/how-to-advertise-networks-in-bgp/1235/75?u=lagapides
https://networklessons.com/cisco/ccna-200-301/ip-routing-explained
https://networklessons.com/cisco/ccna-200-301/introduction-to-administrative-distance