Pcornel
Browse topics
Options
Recent
Favorites
Networking · Technical reference

SPF (Shortest Path First)

Direct answer

SPF (Shortest Path First, Dijkstra's algorithm) is how OSPF calculates routes: each router puts itself at the root and computes the lowest-cost path to every destination in its LSDB. SPF reruns when topology LSAs change.

When to use this

Use it when the design or fault is specifically about the Shortest Path First calculation that turns LSDB topology into loop-free route candidates using cumulative OSPF cost. Stay on that boundary until configuration intent, live control/security state and the adjacent dependency agree.

First 30 seconds

1. SPF (Dijkstra) computes the shortest path tree from the LSDB.

2. Runs on topology changes.

3. SPF throttle timers control frequency.

4. Partial SPF handles type 3/5 changes.

5. Frequent runs mean instability.

Operational verification

LSDB change → SPF throttle → SPF run → RIB update

Context & applicabilityCommon mistakes · platform/version boundaries
Platform / version applicability
Protocol standard + deployed implementation
applies
Structured applicability is explicit Topic metadata; it does not infer compatibility beyond the stored rows.
At a glance

Operational reference

Fast context before you go deeper.

PlatformProtocol standard · IOS/IOS XE · Cisco IOS XE
Key commandshow ip ospf statistics
Scope / prerequisiteUse it when the design or fault is specifically about the Shortest Path First calculation that turns LSDB topology into…
Show · 1
What next?3 suggested next steps
Catalog command links1
Evidence1
On this pageJump to a specific section
Verification

Show Commands

Read-only Cisco show commands for confirming state, narrowing a fault and interpreting the current boundary.

Operational workflow

Verification & Troubleshooting

Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.

6 steps Observe → verify → isolate → change minimally → repeat the original test.
ObservedRecord what the original test actually shows

Capture the concrete output, symptom, packet, log or counter before changing anything.

Step 1 First 30 seconds Verify boundary

Immediate answer: Verify the relevant LSAs and topology inputs first, then compare the SPF result to the route actually installed for the prefix.

Verification chain: LSDB inputs → SPF topology → computed path/cost → OSPF route candidate → RIB preference → CEF adjacency

Stop condition: A plausible SPF cost does not show the OSPF candidate wins the RIB or that the selected next hop forwards successfully.

Step 2 Operational verification and known-good state Verify boundary
show ip ospf | include SPF
show ip ospf statistics
show ip ospf interface brief
show ip route ospf

The first shows the run counter and the time of the last run per area. The statistics view lists recent runs with their duration and the reason. The interface view gives the cost of each OSPF interface, which is what the calculation adds up. The routing table shows the outcome, with [110/<cost>] on each route.

Known-good: the run counter is steady, each route's cost equals the sum of interface costs along its path, and equal-cost paths appear together where intended.

Step 3 Verification and output interpretation Verify boundary

Verify the LSDB topology first, then inspect OSPF route/path information and interface costs to explain the calculated result. SPF counters/timing can show that recalculations occurred, but correlate them to actual LSA changes before assigning significance. If OSPF calculated a path that is absent from the RIB, inspect competing route sources and administrative distance. If the RIB is correct but traffic fails, continue to CEF/adjacency and downstream forwarding evidence. A route cost in the RIB is useful evidence only after you know the route type and topology context. A useful verification chain is interface/role → neighbor or LSDB object → OSPF calculation → RIB → CEF, with each transition independently confirmed.

Step 4 Verification & troubleshooting Narrow the fault

1. show ip ospf | include SPF → how many times SPF has run in each area and when it last ran.

2. A count that climbs quickly: show ip ospf statistics shows recent runs and what triggered them.

3. An unexpected path: add up the costs along both paths with show ip ospf interface brief on each router.

4. LSA present but no route: check the two-way condition, the route-type preference, and whether another routing source holds the prefix.

Step 5 Failure signatures and troubleshooting branches Narrow the fault
  • The SPF counter climbs steadily. A link somewhere in the area is flapping, and every router pays for it.
  • The path is not the one with fewest hops. Cost follows bandwidth. With the default reference bandwidth, every link of 100 Mb/s or more costs 1 and fast links are not distinguished.
  • A higher-cost intra-area path wins over a cheaper inter-area path. Route-type preference.
  • Only one of two expected equal paths is used. Their costs differ by a little, or maximum-paths is 1.
  • The LSA is in the database but there is no route. The two-way check fails for a link on the way.
  • Convergence is slow during a period of flapping. The throttle timers have backed off.
Step 6 When the problem is really fixed Narrow the fault
  • The SPF counter is stable over time.
  • Route costs match the sum of interface costs on the intended path.
  • Equal-cost paths are installed where the design calls for them.
  • The link that caused repeated runs has been identified and repaired.
Evidence references

Evidence · 1 on this Topic

Expected observations and documentation recipes are reference material. Record actual output, device identity, scope and time before claiming a verified result.

observation · 1
Command lookup Jump straight to Cisco syntax
Key points

Do not infer service health from one command. For SPF, distinguish configured intent, protocol/security state, installed forwarding state and the original workload result.

Key checks
  • show ip ospf statistics — SPF runs and timing
  • show ip route ospf — SPF result
ReferenceWhat it is1 section · depth on demand

What it is

SPF — shortest path first, Dijkstra's algorithm — is the calculation every OSPF router runs on its link-state database to find the lowest-cost path to each destination in the area, with itself as the root of the tree. The results are OSPF's candidates for the routing table.

ReferenceWhy it matters1 section · depth on demand

Why it matters

SPF is where the map turns into routes. It explains why all routers agree without loops, why a cost change anywhere can move routes everywhere, and why an unstable link is expensive: every change inside the area makes every router in the area recalculate.

ReferenceImportant terms & boundaries6 sections · depth on demand

Key points

  • Runs separately for each area.
  • A change in a Router or Network LSA triggers a full run; changes in summary and external LSAs need only a partial calculation.
  • Cost to a destination = the sum of the outgoing interface costs along the path.
  • Equal-cost paths are installed together, up to maximum-paths.
  • Route types are preferred in a fixed order regardless of cost: intra-area (O), then inter-area (O IA), then external type 1, then external type 2.
  • A link is used only if both routers report each other in their LSAs.
  • Runs are spaced out by throttle timers that back off while changes keep arriving.

In depth

SPF: computing the shortest-path tree from the LSDB

The Catalyst 9000 OSPF guide states that each device runs the SPF (Dijkstra) algorithm on its LSDB to compute least-cost paths. RFC 2328 adds that the calculation is done separately for each area. The router places itself at the root, adds the lowest-cost reachable node, repeats until every node is reached, and installs routes from the resulting tree.

SPF runs (Catalyst 9300 defaults)

TimerDefault
SPF delay (start)50 ms
SPF hold time200 ms
Commandtimers throttle spf <delay> <hold> <max-wait> (1–600000 ms)

With throttling, the first SPF after a change runs quickly, and repeated changes back off up to the maximum wait. That keeps a flapping link from running SPF continuously.

R1(config)# router ospf 1
R1(config-router)# timers throttle spf 50 200 5000
R1# show ip ospf | include SPF|executed
 Initial SPF schedule delay 50 msecs
 Minimum hold time between two consecutive SPFs 200 msecs
 Maximum wait time between two consecutive SPFs 5000 msecs
    SPF algorithm last executed 00:12:44.120 ago
    SPF algorithm executed 37 times
R1# show ip ospf statistics

Full versus partial SPF

ChangeCalculation
Router or network LSA in the area changes (topology)Full SPF for that area
Only a prefix changes (stub link, summary or external LSA)Partial calculation: the tree is reused

That's why area design matters: topology changes in another area arrive only as summary LSAs and trigger at most a partial calculation.

Monitoring

ObservationMeaning
SPF count rises steadilyA flapping link or router somewhere in the area
show ip ospf statistics shows long SPF timesVery large area; consider splitting it
Router ID in rapidly changing LSAsWhere the instability comes from

Documented example, not captured output.

Source basisSource attribution states what this section is based on; it is not independent proof that the current environment matches it.

Quick reference

SPF (Dijkstra's algorithm) calculates the shortest-path tree from the router to every destination in its area, using the costs in the LSDB. Inter-area and external routes are then added on top of the intra-area tree.

show ip ospf statistics
router ospf 1
 timers throttle spf 50 200 5000

Documented example, not captured output.

SPF throttling delays and spaces out recalculations during instability; frequent SPF runs in show ip ospf statistics indicate a flapping link or router somewhere in the area.

Source basisSource attribution states what this section is based on; it is not independent proof that the current environment matches it.

Mechanics and state ownership

The algorithm starts with the router itself and repeatedly adds the nearest router or network not yet in the tree, noting the total cost and the first hop used to reach it. When everything reachable has been added, the tree gives the best path and next hop to every router in the area. The networks attached to those routers are then added as destinations.

Before a link is used, SPF checks that it is reported from both ends. If router A lists B as a neighbour but B does not list A, the link is ignored. This is why an LSA can be present in the database while the routes behind it are missing.

After the intra-area tree is complete, summaries from area border routers and external routes from AS boundary routers are attached to it. That order is the reason an intra-area path is always preferred over an inter-area one, whatever the costs.

Runs are throttled. The first change is acted on after a short delay; if changes keep coming, the wait between runs grows up to a maximum. This protects the CPU during instability, at the price of slower reaction while the instability lasts.

State model and technical mechanics

Shortest Path First processing builds a shortest-path tree rooted at the local router from the link-state topology represented in the LSDB. OSPF interface costs provide the metric used for topology path comparison; after the topology tree is built, OSPF derives reachable prefixes and route types through additional calculations. SPF is triggered or scheduled when relevant topology information changes, with implementation timers/throttling used to avoid excessive recalculation during churn. The result is OSPF’s candidate route set, not the final forwarding table. RIB selection and CEF programming occur after SPF and can yield a different operational outcome from “shortest OSPF path exists.” For SPF, keep the local interface and area context attached to every state observation, because the same label can have different meaning on point-to-point versus multiaccess links or on an ABR versus an internal router.

Limits and common misconceptions

SPF is not a continuous packet-by-packet path chooser. It calculates control-plane paths from the LSDB; CEF forwards packets afterward. “Shortest” means lowest OSPF cost under the protocol model, not necessarily lowest latency, highest bandwidth or best application performance. An SPF run is also not automatically an incident—topology change legitimately requires recalculation. Keep LSDB correctness, SPF result, RIB installation and data-plane forwarding separate.

ReferenceConfiguration & state1 section · depth on demand

Design and configuration model

Use interface cost and reference-bandwidth policy consistently so SPF expresses the intended routing design. Avoid arbitrary per-link cost tuning without documenting why a path should be preferred, because small local edits can change many shortest-path results. Stable topology reduces repeated SPF work; area design controls the topology scope each SPF calculation sees. Equal-cost paths can legitimately produce ECMP when the platform and route type support it. Keep policy boundaries such as summarization, external metric types and redistribution separate from the pure intra-area shortest-path calculation. This makes a later Round-trip update able to distinguish a design choice from accidental drift and prevents a local OSPF setting from being treated as an unrelated application or transport fix.

Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Technical verification history

Verification history & basis

When and against what this Topic was checked. Later text edits do not count as a new check.

2026-09-14 · vendor docProtocol standard + deployed implementation RFC 2328

Authoritative/upstream documentation reviewed for bounded claims in Routing → OSPF → OSPF Fundamentals → SPF. Documentation verification only; this is not observed lab or production Evidence.

Basis: https://www.rfc-editor.org/rfc/rfc2328.html · confidence 94%
Embedded reference data

Quick lookup tables

SPF · technical reference

Compact OSPF/FHRP mechanics, design and evidence boundaries for fast lookup.

ItemMeaning
InputArea topology in LSDB
MetricOSPF cost
OutputOSPF candidate paths/routes
Later stagesRIB selection then CEF forwarding

SPF operational reference

Topic-specific bounded interpretation: known-good state, suspicious signatures and the next technical proof boundary.

BoundaryKnown-good for SPFSuspicious signatureNext proof
IntentMatches the Shortest Path First calculation that turns LSDB topology into loop-free route candidates using cumulative OSPF cost designConfiguration differs from design/peerCompare effective configuration
Control/security stateStable expected neighbor/database/binding/election statefrequent SPF runs caused by unstable adjacencies/LSAs, an expected topology node unreachable in the SPF graph, a valid SPF candidate losing RIB selection, or path changes caused by cost topology rather than packet lossInspect protocol/security detail and adjacent state
ForwardingExpected Layer-2 or RIB/FIB/gateway pathControl state exists but traffic path disagreesMAC/ARP/RIB/FIB/CEF proof
ClosureOriginal test passes for explained reasonSymptom moved, was bypassed or protection disabledRegression test
Confirmation

Confirm action

Continue?