How router chooses a route.
A router that has multiple exit to a destined network will decide which route will be in routing table by these:
1st: Choose the route that has the longest prefix match.
2nd: Choose the route that has the lowest administrative distance. Administrative distance is a value a router uses to trust a route, if the route has multiple exits to the destined network.
3rd: Choose the route that has the lowest metric.
Default administrative distance
Directly connected route: 0
Static route that uses the interface to exit: 0 (directly connected route is more trusted than this)
Static route: 1
eBGP: 20
Internal EIGRP: 90
IGRP (deprecated): 100
OSPF: 110
IS-IS: 115
RIP: 120
On-Demand Routing (Cisco proprietary; uses CDP): 160
External EIGRP: 170
iBGP: 200
Unknown network: 255
Exceptions to the 3 decision
1. If multiple routes to the same destination exists, and if the routes all have the same administrative distance, load balance will occur.
2. If the route has changed AD, the tie-breaker will be the default administrative distance. Example RIPv2 AD is changed from 120 to 10, and OSPF exists but OSPF is using the default AD, the router will choose RIPv2.
3. Only the best route will be placed in route information base which is reflected in router’s routing table.
4. If multiple OSPF routes exists for the same destination, the router chooses the best route to the destination based on this priority:
OSPF of the same area (intra-area OSPF route) is trusted first.
OSPF of the different area (inter-area OSPF route) is trusted second.
OSPF of type 1 (metric increments) is trusted third.
OSPF of type 2 (metric is unchanged) is trusted last.