Routers use the lowest cost routes to reach a destination. Put another way, routers use the routes that are the easiest and/or fastest way to get somewhere. Cost doesn't have anything to do with the amount of money required to use a connection, but an administrator can configure the metrics to be worse on communications paths that cost more money and thus make communications links that cost less money to be more preferred. This was part of why metrics were originally developed, however high speed communications links have dropped in price dramatically since the early days of the Internet.
The cost of a route is calculated using what are called routing metrics. Routing metrics are assigned to routes by routing protocols to provide measurable values that can be used to judge how useful (how low cost) a route will be. The most useful routes are inserted into the IP routing table on the router. Routes may have more than one metric and the metrics used may be exchanged between routers, or it may be entirely local to that one router. Metrics provide a quantitative value to indicate the specific characteristics of the route.
The simplest example of a metric is the weight value. Many different routers can use static routes and static routes can be assigned a weight. Higher weight means higher cost. This allows the administrator to create several routes to a destination and then set them up so that one will be preferred over the others, or so that two or more will be used equally. Assigning a route a higher weight causes that route to be less preferred and will not be used until all the more preferred routes with lower weights are no longer available. Equal weights make the static routes equally preferred.
RIP MetricsRIP is a distance vector protocol which uses hop count to determine the best path through the network. The path with the fewest number of routed hops is considered the shortest path.
The primary OSPF metric is cost, which Cisco and other manufacturers configure to be "inversely proportional to the bandwidth of that interface". Lower cost means a faster interface and shorter end-to-end transmission times and thus the shortest path. The bandwidth of an interface is indirectly passed on with the OSPF route in the form of an additive 'cost' metric to indicate the speed of the entire path to the destination via the local interface link. Because Open Shortest Path First (OSPF) is a dynamic link state routing protocol, higher speed links have a lower cost than low speed links.