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.
SPF (Shortest Path First)
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.
Context & applicabilityCommon mistakes · platform/version boundaries
Operational reference
Fast context before you go deeper.
show ip ospf statisticsShow Commands
Read-only Cisco show commands for confirming state, narrowing a fault and interpreting the current boundary.
Verification & Troubleshooting
Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.
Use the operational verification above to establish the expected state.
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-pathsis 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 · 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.
Do not infer service health from one command. For SPF, distinguish configured intent, protocol/security state, installed forwarding state and the original workload result.
show ip ospf statistics— SPF runs and timingshow 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)
| Timer | Default |
|---|---|
| SPF delay (start) | 50 ms |
| SPF hold time | 200 ms |
| Command | timers 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
| Change | Calculation |
|---|---|
| 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
| Observation | Meaning |
|---|---|
| SPF count rises steadily | A flapping link or router somewhere in the area |
show ip ospf statistics shows long SPF times | Very large area; consider splitting it |
| Router ID in rapidly changing LSAs | Where the instability comes from |
Documented example, not captured output.
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.
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
Verification history & basis
When and against what this Topic was checked. Later text edits do not count as a new check.
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%Quick lookup tables
SPF · technical reference
Compact OSPF/FHRP mechanics, design and evidence boundaries for fast lookup.
| Item | Meaning |
|---|---|
| Input | Area topology in LSDB |
| Metric | OSPF cost |
| Output | OSPF candidate paths/routes |
| Later stages | RIB selection then CEF forwarding |
SPF operational reference
Topic-specific bounded interpretation: known-good state, suspicious signatures and the next technical proof boundary.
| Boundary | Known-good for SPF | Suspicious signature | Next proof |
|---|---|---|---|
| Intent | Matches the Shortest Path First calculation that turns LSDB topology into loop-free route candidates using cumulative OSPF cost design | Configuration differs from design/peer | Compare effective configuration |
| Control/security state | Stable expected neighbor/database/binding/election state | frequent 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 loss | Inspect protocol/security detail and adjacent state |
| Forwarding | Expected Layer-2 or RIB/FIB/gateway path | Control state exists but traffic path disagrees | MAC/ARP/RIB/FIB/CEF proof |
| Closure | Original test passes for explained reason | Symptom moved, was bypassed or protection disabled | Regression test |