OSPF Overview – Open Shortest Path First Explained

1. What is OSPF?

OSPF (Open Shortest Path First) is an open-standard, link-state Interior Gateway Protocol (IGP) defined in RFC 2328 (OSPFv2 for IPv4) and RFC 5340 (OSPFv3 for IPv6). It is the most widely deployed IGP in enterprise and service-provider networks and is a core topic in the CCNA exam.

Unlike distance-vector protocols such as RIP, OSPF routers build a complete map of the network topology — called the Link-State Database (LSDB) — and run Dijkstra's Shortest Path First algorithm on that map to independently calculate the best loop-free path to every destination.

OSPF PropertyValue
Protocol typeLink-state IGP
StandardOpen standard — RFC 2328 (v2 for IPv4), RFC 5340 (v3 for IPv6)
AlgorithmDijkstra's SPF (Shortest Path First)
MetricCost (based on interface bandwidth)
Administrative Distance (AD)110
TransportIP protocol number 89 — not TCP or UDP
Multicast addresses224.0.0.5 (all OSPF routers), 224.0.0.6 (DR/BDR only)
Supports VLSM / CIDRYes — classless routing protocol
Supports IPv6Yes — via OSPFv3
Supports hierarchical designYes — via multi-area OSPF with mandatory backbone Area 0

Related pages: Administrative Distance | Route Sources | Routing Metrics | Default Routes | GRE Tunnels (OSPF over GRE) | Protocols Overview | OSI Model

2. Link-State vs Distance-Vector

Understanding what makes OSPF a link-state protocol — and how that differs from distance-vector — is fundamental to grasping why OSPF behaves the way it does.

Feature Link-State (OSPF) Distance-Vector (RIP) Advanced Distance-Vector (EIGRP)
What each router knowsComplete topology map (LSDB)Only its neighbour's routing tableNeighbour's metrics + topology table
AlgorithmDijkstra's SPFBellman-FordDUAL (Diffusing Update Algorithm)
MetricCost (bandwidth-based)Hop count (max 15)Composite (bandwidth + delay + load + reliability)
UpdatesTriggered; full LSA refresh every 30 minPeriodic (every 30 s); full tableTriggered; partial updates only
Convergence speedFastSlow (counting to infinity problem)Very fast (DUAL guarantees loop-free backup)
ScalabilityHigh — scales with multi-area designLow — 15-hop maximum limitHigh — supports large networks
Loop preventionSPF on identical LSDB guarantees loop-free pathsSplit horizon, route poisoningDUAL feasibility condition
Open standardYesYesPartially (Cisco advanced features)

Related pages: RIP Concepts | EIGRP Overview | BGP Overview

3. How OSPF Works — Step by Step

OSPF brings up a routing domain through a well-defined sequence of steps. Every OSPF router goes through these phases — understanding them is critical for both configuration and troubleshooting.

  Step 1: Discover Neighbours
  ┌──────────────────────────────────────────────────────────────────┐
  │  Routers send Hello packets every 10 s (broadcast) / 30 s (NBMA)│
  │  Hello contains: Router ID, area ID, hello/dead timers, network  │
  │  mask, DR/BDR info, and neighbour list                           │
  └──────────────────────────────────────────────────────────────────┘
             ↓
  Step 2: Form Adjacencies
  ┌──────────────────────────────────────────────────────────────────┐
  │  Two neighbours exchange DBD (Database Description) packets      │
  │  to compare their LSDBs, then request missing LSAs via LSR       │
  │  (Link-State Request). The neighbour replies with LSU            │
  │  (Link-State Update). LSAck confirms receipt.                    │
  └──────────────────────────────────────────────────────────────────┘
             ↓
  Step 3: Flood LSAs — Build the LSDB
  ┌──────────────────────────────────────────────────────────────────┐
  │  Each router generates Type 1 (Router) LSAs describing its own   │
  │  links. The DR generates Type 2 (Network) LSAs on broadcast      │
  │  segments. All LSAs flood within the area until every router     │
  │  has an identical LSDB.                                          │
  └──────────────────────────────────────────────────────────────────┘
             ↓
  Step 4: Run SPF — Calculate Best Paths
  ┌──────────────────────────────────────────────────────────────────┐
  │  Each router independently runs Dijkstra's SPF algorithm on its  │
  │  LSDB to build a shortest-path tree (SPT) rooted at itself.      │
  │  The best path to each destination is installed in the routing   │
  │  table as an OSPF route (O or O IA).                             │
  └──────────────────────────────────────────────────────────────────┘
             ↓
  Step 5: Maintain — Hello keepalives + LSA refreshes
  ┌──────────────────────────────────────────────────────────────────┐
  │  Hello packets maintain neighbour relationships (dead timer =    │
  │  4 x hello interval). LSAs are re-flooded every 30 minutes.     │
  │  Any topology change triggers a new LSA flood + SPF recalc.     │
  └──────────────────────────────────────────────────────────────────┘
    

Related pages: OSPF Neighbor States | OSPF DR/BDR | OSPF Areas & LSAs

4. OSPF Router ID (RID)

Every OSPF router must have a unique Router ID (RID) — a 32-bit value written in dotted-decimal notation (like an IP address) that identifies the router within the OSPF domain. Duplicate Router IDs cause adjacency and routing failures.

Router ID Selection Order (highest wins)

PrioritySourceNotes
1 (highest)Manually configured with router-id commandBest practice — always configure this explicitly
2Highest IP address on a loopback interfaceLoopbacks never go down — more stable than physical interfaces
3 (fallback)Highest IP address on any active physical interface at OSPF start-upRisky — can change if the interface goes down and OSPF restarts
! Best practice — always manually set the Router ID
router ospf 1
 router-id 1.1.1.1

! Verify the Router ID
Router# show ip ospf
! Look for: "Router ID 1.1.1.1"

! After changing router-id, clear OSPF process to apply the new RID
Router# clear ip ospf process
! WARNING: This drops all OSPF adjacencies temporarily
Exam tip: The Router ID is chosen at OSPF process start-up. If you change it, you must use clear ip ospf process for the new RID to take effect. The RID does not have to be reachable or even match an actual interface — it is simply a unique identifier for the router within the OSPF domain.

5. OSPF Cost — The Metric

OSPF uses cost as its metric — a dimensionless value inversely proportional to interface bandwidth. Lower cost = preferred path. The total cost of a route is the cumulative cost of all outgoing interfaces along the entire path.

Cost Formula

  Cost = Reference Bandwidth / Interface Bandwidth

  Default reference bandwidth = 100 Mbps (100,000,000 bps)

  Interface costs with default reference bandwidth:
  ┌──────────────────────────┬────────────────────────────────────────┐
  │ Interface Type            │ Cost                                   │
  ├──────────────────────────┼────────────────────────────────────────┤
  │ 10 Mbps Ethernet          │ 100 / 10    = 10                       │
  │ 100 Mbps FastEthernet     │ 100 / 100   = 1                        │
  │ 1 Gbps GigabitEthernet    │ 100 / 1000  = 0.1  → rounds up to 1   │
  │ 10 Gbps TenGigabitEth.    │ 100 / 10000 = 0.01 → rounds up to 1   │
  └──────────────────────────┴────────────────────────────────────────┘

  Problem: GigE, 10GigE, and 100GigE all get cost = 1 with default reference.
  OSPF cannot differentiate them — it may choose a slower path!
  Fix: change reference-bandwidth to 10000 (10 Gbps) or 100000 (100 Gbps).
    
! Fix: increase reference bandwidth so GigE and 10GigE get distinct costs
router ospf 1
 auto-cost reference-bandwidth 10000    ! Units are Mbps — this sets 10 Gbps
! Apply this on ALL routers in the OSPF domain — must be consistent

! Or manually override cost on a specific interface
interface GigabitEthernet0/1
 ip ospf cost 50

! Verify interface cost
Router# show ip ospf interface GigabitEthernet0/1
! Look for: "Cost: 50"

Related pages: Routing Metrics | show ip protocols | show interfaces

6. OSPF Packet Types

OSPF uses five packet types — all carried directly in IP (protocol 89) without TCP or UDP. Understanding each packet is essential for reading debug output and diagnosing adjacency problems.

Type Name Purpose When Sent
1 Hello Discover and maintain neighbours; elect DR/BDR on broadcast segments Every hello interval (10 s on broadcast/P2P, 30 s on NBMA). Sent to 224.0.0.5.
2 DBD (Database Description) Exchange LSDB summaries during adjacency formation — lists LSA headers without full content During ExStart and Exchange states of adjacency formation
3 LSR (Link-State Request) Request specific LSAs that are missing or outdated after comparing DBDs After DBD exchange, when a router discovers it needs specific LSAs
4 LSU (Link-State Update) Deliver the actual LSA content in response to an LSR, or to flood a topology change In response to LSR; also triggered by any topology change
5 LSAck (Link-State Acknowledgement) Acknowledge received LSUs — ensures reliable flooding After receiving an LSU

Hello Packet — Fields That Must Match for Adjacency

The Hello packet contains several fields that must match between neighbours for an adjacency to form. A mismatch silently prevents adjacency — the routers see each other's Hellos but never advance beyond Init or 2-Way.

Hello FieldMust Match?Notes
Area ID✅ YesBoth interfaces must be in the same OSPF area
Hello interval✅ YesDefault 10 s (broadcast/P2P), 30 s (NBMA)
Dead interval✅ YesDefault 4 × hello interval (40 s on broadcast)
Subnet mask✅ Yes (broadcast)Not checked on point-to-point links
Area type (stub flag)✅ YesBoth must agree on stub/NSSA; mismatch blocks adjacency
Authentication✅ YesType and key must match if configured
Router IDMust be uniqueDuplicate RIDs cause routing problems throughout the domain
MTU⚠️ Should matchMTU mismatch causes DBD exchange failure (stuck at ExStart)

Related pages: OSPF Neighbor States | OSPF DR/BDR | Debug Commands

7. OSPF Neighbour States — Summary

OSPF adjacency formation progresses through eight states. A healthy, fully converged adjacency ends at the Full state. Each state represents a distinct phase of the relationship between two routers.

  Down → Init → 2-Way → ExStart → Exchange → Loading → Full

  Down     — No Hello received from this neighbour yet
  Init     — Hello received but our Router ID is NOT yet in their neighbour list
  2-Way    — Bidirectional communication confirmed (our RID is in their Hello)
             ★ DR/BDR election takes place here on broadcast segments
  ExStart  — Master/slave relationship negotiated for DBD exchange
  Exchange — DBD packets exchanged (LSDB header summaries compared)
  Loading  — LSRs sent; missing LSAs received via LSUs
  Full     — LSDBs are identical ✅ — fully adjacent, routing is active
    
Important: On broadcast networks (Ethernet), only DR and BDR reach Full state with each other and with all DROther routers. DROther routers stay at 2-Way with each other — this is completely normal and expected, not a problem or misconfiguration.

For the complete neighbour state machine with causes and troubleshooting steps: OSPF Neighbor States — Full Guide

8. DR and BDR Election

On multi-access broadcast networks (Ethernet), OSPF elects a Designated Router (DR) and a Backup Designated Router (BDR) to reduce adjacency overhead. Without DR/BDR, every pair of routers on the segment would form a full adjacency — creating an n(n-1)/2 adjacency explosion on large segments.

RoleFunctionAdjacency Behaviour
DRCollects and re-floods LSAs for the entire segment. Generates the Type 2 Network LSA.Full adjacency with ALL routers on the segment
BDRListens passively to all exchanges; takes over instantly if the DR fails.Full adjacency with ALL routers on the segment
DROtherAll other routers — send/receive LSAs only through the DR and BDR.2-Way with other DROthers; Full only with DR and BDR

DR/BDR Election Rules

PriorityCriterionNotes
1 (highest)Highest OSPF interface priority (0–255)Default priority = 1. Setting priority to 0 prevents a router from ever becoming DR or BDR.
2 (tiebreaker)Highest Router IDUsed only when priorities are equal
! Set interface priority to influence DR election (higher = preferred DR)
interface GigabitEthernet0/0
 ip ospf priority 100       ! This router wins DR election on this segment

! Prevent a router from ever becoming DR or BDR
interface GigabitEthernet0/0
 ip ospf priority 0

! Verify current DR/BDR on a segment
Router# show ip ospf interface GigabitEthernet0/0
! Look for: "Designated Router (ID)...", "Backup Designated Router (ID)..."
DR election is non-preemptive. If a new router with a higher priority joins the segment after DR election, it does not take over from the existing DR. The current DR stays in place until it fails or the OSPF process is cleared. Always plan your DR assignments before deployment.

Full guide: OSPF DR/BDR Election — Complete Explanation

9. OSPF Areas — Why They Matter

In a single-area OSPF deployment, every router floods LSAs to every other router and every topology change triggers a full SPF recalculation on every router. In large networks this becomes unsustainable. OSPF areas solve this by confining LSA flooding within each area boundary — a link failure in Area 2 only triggers SPF recalculation on Area 2 routers.

     Area 1                Area 0 (Backbone)              Area 2
  ┌──────────┐         ┌─────────────────────┐         ┌──────────┐
  │ R1 ── R2 │──[ABR]──│  R5 ──── R6         │──[ABR]──│ R9 ──R10 │
  │          │         │  |                  │         │          │
  │  R3      │         │  R7 ── R8 [ASBR]   │         │  R11     │
  └──────────┘         └──────────┬──────────┘         └──────────┘
                                  │ Type 5 External LSAs
                            External / Internet
    
Area ConceptKey Rule
Area 0 (Backbone)Mandatory — all inter-area traffic must transit it. Every area must attach to Area 0 directly or via a virtual link.
ABR (Area Border Router)Router with interfaces in 2+ areas including Area 0. Maintains a separate LSDB per area. Generates Type 3 Summary LSAs to share routes between areas.
ASBR (AS Boundary Router)Redistributes routes from outside OSPF (other IGPs, BGP, static routes) into OSPF as Type 5 External LSAs.
Intra-area routesRoutes within the same area — shown as O in the routing table
Inter-area routesRoutes between areas via ABR — shown as O IA
External routesRoutes redistributed from outside OSPF — shown as O E1 or O E2

For the full deep-dive on area types (Stub, Totally Stubby, NSSA, Totally NSSA), LSA Types 1–7, ABR/ASBR configuration, and virtual links: OSPF Areas & LSAs — Detailed Guide

10. Basic OSPF Configuration

The minimum OSPF configuration requires three things: enabling OSPF with a process ID, assigning a Router ID, and advertising networks into OSPF using the network command with a wildcard mask and area assignment.

! ── Minimal OSPF single-area configuration ──────────────────────────────
router ospf 1                                   ! Process ID 1 — local significance only
 router-id 1.1.1.1                              ! Manually set Router ID (best practice)
 network 192.168.1.0 0.0.0.255 area 0           ! Advertise this network into Area 0
 network 10.0.0.0 0.0.0.3 area 0                ! Point-to-point link in Area 0

! ── Passive interface — suppress Hellos on user-facing interfaces ────────
router ospf 1
 passive-interface GigabitEthernet0/1           ! No OSPF Hellos on this interface
 ! The network is still advertised — Hellos are just suppressed

! ── Alternatively: set all interfaces passive, then enable selectively ──
router ospf 1
 passive-interface default
 no passive-interface GigabitEthernet0/0        ! Only this interface sends Hellos
! ── Essential verification commands ─────────────────────────────────────

! Show OSPF neighbours and their current state (target: Full or 2-Way)
Router# show ip ospf neighbor

! Show OSPF-learned routes (O = intra-area, O IA = inter-area, O E1/E2 = external)
Router# show ip route ospf

! Show OSPF process details: Router ID, area count, SPF statistics
Router# show ip ospf

! Show per-interface OSPF settings: cost, timers, DR/BDR, network type
Router# show ip ospf interface

! Show the Link-State Database (all LSA types)
Router# show ip ospf database

! Show which networks OSPF is advertising and other protocol parameters
Router# show ip protocols

Related pages: OSPF Single-Area Configuration — Full Lab | show ip route | show ip protocols | show ip interface brief | show running-config

Step-by-step labs: OSPF Single-Area Lab | OSPF Multi-Area Lab | Default Route Redistribution into OSPF | Troubleshooting OSPF Adjacency Lab

11. OSPF vs EIGRP vs RIP — Quick Comparison

Feature OSPF EIGRP RIP v2
Protocol typeLink-stateAdvanced distance-vectorDistance-vector
StandardOpen — RFC 2328Cisco (RFC 7868 partial)Open — RFC 2453
AlgorithmDijkstra SPFDUALBellman-Ford
MetricCost (bandwidth)Composite (BW + delay + …)Hop count
AD11090 internal / 170 external120
Max hop countNone (area-based scalability)100 default / 255 max15 hops (16 = unreachable)
Supports VLSMYesYesYes (v2 only)
Supports IPv6Yes — OSPFv3Yes — EIGRPv6Yes — RIPng
ConvergenceFastVery fastSlow
ScalabilityHigh — multi-area designHighLow
TransportIP protocol 89 (multicast)IP protocol 88 (multicast/unicast)UDP port 520
Best used whenMulti-vendor enterprise or SP networksCisco-only enterprise networksVery small or lab networks only

12. Common OSPF Problems and Fixes

SymptomLikely CauseFix / Diagnostic Command
Routers stay in Init state ACL blocking multicast 224.0.0.5; wrong area ID; duplex/speed mismatch show ip ospf neighbor — verify area ID; check for ACL dropping Hello packets
Routers stay at 2-Way Expected between DROthers on a broadcast segment Normal — only DR and BDR reach Full state; 2-Way between DROthers is correct
Stuck at ExStart / Exchange MTU mismatch between neighbours show ip ospf interface — compare MTU values; use ip ospf mtu-ignore to confirm cause; fix MTU
No adjacency — Hello mismatch Mismatched hello/dead timers, area type, subnet mask, or authentication debug ip ospf hello — compare all hello fields on both sides
Routes missing from routing table Network not advertised; wrong area in network statement; passive-interface blocking Hellos show ip route ospf; show ip protocols; verify network commands
Routes present but suboptimal path chosen GigE and FastEthernet both have cost 1 (default reference bandwidth too low) Set auto-cost reference-bandwidth 10000 on all routers
Adjacency flapping Unstable link; duplicate Router IDs; dead timer expiry on unreliable link show ip ospf — check for duplicate RIDs; debug ip ospf events to trace flap cause
External routes missing Redistribution not configured on ASBR; area is stub (blocks Type 5 LSAs) show ip ospf database external — verify Type 5 LSAs exist; check ASBR redistribute command

Related pages: Troubleshooting Methodology | Troubleshooting Connectivity | Debug Commands | debug ip packet | Troubleshooting OSPF Adjacency Lab | Troubleshooting Layer 3 Routing Lab

13. Key Points Summary

TopicKey Facts
What is OSPFOpen-standard link-state IGP (RFC 2328 v2, RFC 5340 v3); uses IP protocol 89; classless
AlgorithmDijkstra's SPF runs on an identical LSDB — guarantees loop-free paths
MetricCost = Reference BW / Interface BW; lower = preferred; increase reference BW for GigE+ networks
AD110 — preferred over RIP (120); less trusted than EIGRP internal (90) or static routes (1)
Router IDManual > Highest Loopback IP > Highest Physical IP; must be unique; change requires clear ip ospf process
Hello interval10 s on broadcast/P2P; 30 s on NBMA — must match on both sides for adjacency
Dead interval4 × hello interval (40 s default on broadcast) — must match on both sides
5 Packet typesHello (discover), DBD (compare), LSR (request), LSU (deliver), LSAck (acknowledge)
DR/BDRElected on broadcast segments; highest priority then highest RID; non-preemptive; DROthers stay 2-Way with each other
Multicast224.0.0.5 = all OSPF routers; 224.0.0.6 = DR and BDR only
AreasArea 0 is mandatory backbone; ABRs connect areas; LSA flooding confined per area; reduces SPF scope
Route codesO = intra-area; O IA = inter-area; O E1/E2 = external (redistributed from outside OSPF)
LSA refreshEvery 30 minutes (LSRefreshTime); MaxAge = 60 minutes; sequence numbers prevent stale data

OSPF Overview Quiz

1. What type of routing protocol is OSPF, and what does that mean for how routers learn the topology?

Correct answer is C. OSPF is a link-state protocol. Every router floods LSAs (Link-State Advertisements) to all other routers in its area so they all build an identical LSDB — a complete map of the topology. Each router then independently runs Dijkstra's SPF algorithm on that map to calculate the loop-free shortest path to every destination. This is fundamentally different from distance-vector protocols like RIP, where each router only knows what its direct neighbours tell it.

2. What is the OSPF metric, and why is the default reference bandwidth a problem in modern networks?

Correct answer is B. OSPF cost = reference bandwidth / interface bandwidth. The default reference bandwidth is 100 Mbps. A 100 Mbps FastEthernet interface gets cost 1 (100/100 = 1). A 1 Gbps GigabitEthernet interface also gets cost 1 (100/1000 = 0.1 → rounds up). Even a 10 GigE interface gets cost 1. OSPF cannot distinguish between them and may choose a slower path. Fix this with auto-cost reference-bandwidth 10000 (for 10 Gbps reference) on ALL routers in the domain.

3. How is the OSPF Router ID determined if it is not manually configured?

Correct answer is D. OSPF Router ID selection follows this priority order: (1) manually configured router-id command — always wins and is best practice; (2) highest IP address among all configured loopback interfaces — loopbacks are always up, making this stable; (3) highest IP address on any active physical interface when OSPF starts — risky because if that interface goes down and OSPF restarts, the RID can change. Always manually set the Router ID to a loopback address for predictable and stable operation.

4. Which OSPF packet maintains neighbour relationships, and what happens if it stops being received?

Correct answer is A. OSPF Hello packets (Type 1) are sent at the hello interval — every 10 seconds on broadcast and point-to-point links, every 30 seconds on NBMA networks. They are sent to multicast 224.0.0.5 (all OSPF routers). Each router tracks when it last received a Hello from each neighbour. If no Hello arrives within the dead interval (default = 4 × hello = 40 s on broadcast), that neighbour is declared down, the adjacency goes to Down state, all routes learned from that neighbour are removed, and SPF recalculates.

5. Why are DR and BDR elected on broadcast Ethernet segments, and which state do DROther routers reach with each other?

Correct answer is C. Without DR/BDR on a broadcast segment with n routers, you would need n(n-1)/2 full adjacencies. With DR/BDR, only the DR and BDR form Full adjacency with every other router — DROther routers send all their LSUs to 224.0.0.6 (AllDRouters) so only DR and BDR receive them, then the DR re-floods to 224.0.0.5. DROther routers stay at 2-Way state with each other — this is completely correct behaviour, not a problem or misconfiguration to fix.

6. An OSPF adjacency between two routers is stuck at ExStart. What is the most likely cause?

Correct answer is B. ExStart/Exchange is the phase where routers exchange DBD (Database Description) packets. If there is an MTU mismatch, the larger DBD packets cannot pass through the interface with the smaller MTU and are dropped — the exchange can never complete, leaving the adjacency stuck at ExStart. Timer mismatches (A) and area type mismatches (C) prevent adjacency earlier, at the Hello/Init phase. Duplicate Router IDs (D) cause routing table problems but the symptom differs. Diagnose with show ip ospf interface and fix with either ip ospf mtu-ignore (temporary) or by matching the actual MTU.

7. What is the Administrative Distance of OSPF, and what happens when both OSPF and EIGRP learn the same prefix?

Correct answer is D. OSPF has an Administrative Distance of 110. AD is the router's measure of trustworthiness of a routing source — lower AD is more trusted. If two routing protocols advertise a route to the same destination, the router installs only the route from the lower-AD source. EIGRP internal (AD 90) beats OSPF (AD 110) — only the EIGRP route appears in the routing table. OSPF beats RIP (AD 120). Static routes have AD 1. Directly connected routes have AD 0.

8. What are the two OSPF multicast addresses used on broadcast networks, and what is the difference between them?

Correct answer is A. OSPF uses two multicast addresses on broadcast networks. 224.0.0.5 (AllSPFRouters) — all OSPF routers listen on this address; used for Hello packets and for the DR to re-flood LSUs to every OSPF router on the segment. 224.0.0.6 (AllDRouters) — only the DR and BDR listen on this address; DROther routers send their LSUs to 224.0.0.6 so that only the DR and BDR receive them. The DR then re-floods the LSU content to 224.0.0.5 so all routers on the segment get the update.

← Back to Home