How OSPF Chooses Paths: Cost, Areas and Route Types
5 min read
OSPF is a link-state routing protocol: every router builds a complete map of its area (the link-state database) and independently computes the shortest path to each destination using Dijkstra's algorithm. "Shortest" in OSPF means lowest total cost — and understanding cost is the key to understanding every OSPF decision.
In simple words
OSPF is like every driver in a city having the same live map. When you ask for directions, the map adds up the "cost" (travel time) of every road on each possible route and picks the route with the lowest total. Every OSPF router holds the same map of its area and does the same maths, so they all agree on the best paths.
Cost: the only metric
OSPF cost for an interface is defined as:
Cost = reference bandwidth ÷ interface bandwidth
The default reference bandwidth is 100 Mbps. So a FastEthernet interface (100 Mbps) gets cost 100/100 = 1, and a GigabitEthernet interface gets 100/1000 = 0.1, which OSPF rounds up to a minimum of 1. That is a real problem on modern networks: a 1 Gbps link and a 100 Gbps link both cost 1, so OSPF sees them as equal. The standard fix is to raise the reference bandwidth (for example to 100 Gbps) on all routers, giving 100 Gbps = 1, 10 Gbps = 10, 1 Gbps = 100, 100 Mbps = 1000 — a metric that actually reflects the links. The total path cost is the sum of the costs of the outgoing interfaces along the path, and the lowest total wins.
Areas, ABRs and the backbone
Large OSPF networks are divided into areas to limit the size of the link-state database. Area 0 is the backbone; all other areas must connect to it (directly or via a virtual link). Routers that sit on area boundaries are ABRs (Area Border Routers); routers that inject routes from outside OSPF (static routes, other protocols) are ASBRs (Autonomous System Boundary Routers). Routes learned from another area appear as O IA (inter-area); routes from outside OSPF appear as E1 or E2 (external).
E1 versus E2: the exam favourite
Both are external routes, but they are compared differently:
- E2 routes use only the external cost (the cost assigned at redistribution). The internal OSPF cost to reach the ASBR is ignored.
- E1 routes add the internal cost to reach the ASBR to the external cost.
So if an ASBR redistributes a route with external cost 20, and reaching that ASBR costs 45: the E2 metric is 20, the E1 metric is 65. E1 versus E1, or E2 versus E2, compares the resulting numbers normally — but note that an E2 route (20) beats an E1 route (65) to the same destination even though they describe the same external network. Use E1 when you want internal topology to influence the choice between exit points; E2 (the default) when the external cost alone should decide.
LSA types in one paragraph
Routers exchange the map using Link-State Advertisements: Type 1 (router) and Type 2 (network) describe the area's topology; Type 3 (summary) carries inter-area routes from the ABR; Type 4 tells routers how to reach an ASBR; Type 5 carries external routes; Type 7 is the external LSA used inside NSSA areas. You rarely need more than that to follow an OSPF design discussion.
Worked example: two paths, one winner
Router R1 needs to reach 10.5.0.0/16. Path A goes through two GigabitEthernet links (cost 1 + 1 = 2) but stays inside the area; Path B uses one GigabitEthernet link (cost 1) but crosses into another area and back. R1 does not care about the area crossing for the cost comparison — it sums interface costs. Path A = 2, Path B = 1, so Path B wins and appears as an O IA route. Now suppose the destination is instead redistributed from a static route with external cost 20, and reaching the ASBR costs 45: as E2 the metric is 20; as E1 it is 65. If a second ASBR offers the same destination as E2 with external cost 30, the comparison is 20 vs 30 — the first ASBR wins.
Path A: R1 → R2 → R4 over two GigabitEthernet links. Path B: one direct GigabitEthernet link R1 → R4.
- Path A: R1 → R2 → R4 over two GigabitEthernet links. Path B: one direct GigabitEthernet link R1 → R4.
- Path A: 1 + 1 = 2.
- Path B: 1.
- Winner — lowest total cost 1 (route type O IA). Path A: total cost 2.
Keeping the database small: areas and stub types
Every router in an area holds every LSA for that area, so the database — and the time Dijkstra takes to run — grows with the area. Hierarchy is how OSPF stays scalable. The ABR can summarise a range of subnets into one Type 3 LSA instead of flooding dozens of them, and special area types filter still more: a stub area blocks Type 5 external LSAs (the ABR injects a default route instead), a totally stubby area blocks Type 3 and Type 5 alike, and an NSSA (not-so-stubby area) permits limited external routes via Type 7 LSAs, which the ABR converts to Type 5. The trade-off is always the same: less detail means a smaller database and faster convergence, but the area loses the ability to pick optimal paths for the hidden destinations and simply follows the default toward the ABR. Design stub areas at the network edge, where the default route is genuinely the right answer.
At a glance: why, where, when, how
- Why: networks need automatic, fast rerouting when a link fails — OSPF recalculates in seconds.
- Where: inside one organisation's network (a campus, a company WAN) — OSPF does not run between companies.
- When: whenever an organisation has multiple paths between sites and wants the best one chosen automatically.
- How: routers share link information, build identical maps, and each runs Dijkstra's algorithm using interface cost, as this article explains.
Advantages and disadvantages
Advantages
- Fast recovery: a failed link triggers a recalculation, not a phone call.
- No loops by design: every router works from the same map.
- Scales with areas: big networks split the map into smaller pieces.
Disadvantages
- More demanding than simpler protocols: every router stores the map and runs the maths.
- The default cost formula treats 1 Gbps and 100 Gbps as equal until you raise the reference bandwidth.
- Design matters: badly drawn area boundaries make troubleshooting harder.
Real-life example
A hospital has two network paths between its main building and its lab building: a fast fibre path and a slow backup radio link. OSPF gives the fibre path a low cost and the radio link a high cost, so traffic uses fibre. The night the fibre is cut by roadworks, OSPF recalculates on its own and lab results keep flowing over the radio link — nobody reconfigures anything at 3 a.m.
FAQ
Why is my 10 Gbps link treated the same as 1 Gbps?
Because the reference bandwidth is still at its 100 Mbps default, so both compute to cost 1. Raise the reference bandwidth consistently on every router and the costs will separate properly.
When would I use E1 instead of E2?
When you have multiple exit points to the same external network and want the internal topology — which exit is genuinely closer — to influence the decision. E2 ignores that entirely.
Does OSPF load-balance?
Yes — up to four equal-cost paths by default (configurable). It is per-destination or per-packet depending on configuration, not per arbitrary flow.
Related: OSPF Path Selection