What this note covers

OSPF chooses paths by cost. This note explains how cost is
calculated, the trap in the default reference bandwidth, the order in
which OSPF prefers route types, and how external routes (E1/E2/N1/N2)
differ.

Cost — the OSPF metric

How cost works

  • OSPF’s metric is cost, based on interface bandwidth.
  • Cost is inversely proportional to bandwidth — higher bandwidth,
    lower cost.
  • The cost of a route is the sum of the outgoing-interface
    costs
    along the path to the destination.
  • Lowest total cost wins.

The cost formula

Added — the actual calculation

Cost = reference bandwidth ÷ interface bandwidth.

  • Default reference bandwidth = 100 Mbps (10⁸ bps).
  • So: 100 Mbps link → cost 1; 10 Mbps → cost 10; T1 (1.544 Mbps) →
    cost ~64.
  • Cost has a minimum of 1 (it’s an integer, rounded down).

Added — the reference-bandwidth trap

With a 100 Mbps default, any link at 100 Mbps or faster gets a cost
of 1
. A FastEthernet (100 M), a 1 G and a 10 G link all look
identical to SPF — it can’t prefer the faster one. On modern
networks you must raise the reference bandwidth so fast links get
distinct costs.

  • Anchor: auto-cost reference-bandwidth <Mbps>.
  • It must be set identically on every router in the domain, or
    cost calculations disagree and paths become inconsistent.

Route selection order

Preference from most to least preferred

When OSPF has multiple ways to reach the same destination, it prefers
by route type first, before comparing cost:

  1. Intra-area (O) — destination inside the same area.
  2. Inter-area (O IA) — destination in another area, via the ABR.
  3. External Type 1 (E1) / NSSA Type 1 (N1).
  4. External Type 2 (E2) / NSSA Type 2 (N2).

A more-preferred type wins even if its cost is higher. Cost only
decides between routes of the same type.

N1/N2 vs E1/E2

N-routes come from an NSSA (Type 7 origin); E-routes come from a
normal Type 5 origin. When metrics to the ASBR are equal, the
N route is preferred over the equivalent E route.

External Type 1 vs Type 2

The core difference — how metric is counted

  • External Type 1 (E1): metric = **redistributed (external) cost
    • internal cost to reach the ASBR**. The cost grows as you move
      through the OSPF domain toward the ASBR. Use when you want to pick
      the path with the shortest total route from within OSPF.
  • External Type 2 (E2): metric = only the redistributed
    (external) cost
    — the internal cost to reach the ASBR is
    ignored. This is the default for redistributed routes.

E2 has a static metric

An E2 route carries a fixed metric (default 20) no matter how
far the ASBR is inside the domain — the internal distance never adds
to it. Two routers at different distances from the ASBR see the
same E2 metric, so E2 alone can’t distinguish “closer to the
exit.” (E1 can, because it adds internal cost.)

Picking E1 vs E2 in practice

  • E1 when internal distance to the exit should matter (multiple
    ASBRs, you want the nearest exit).
  • E2 (default) when you only care about the external cost and want
    simple, predictable metrics.

Quick reference

Route codes you'll see in the routing table

  • O — intra-area
  • O IA — inter-area
  • O E1 / O E2 — external Type 1 / Type 2
  • O N1 / O N2 — NSSA external Type 1 / Type 2