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 Property | Value |
|---|---|
| Protocol type | Link-state IGP |
| Standard | Open standard — RFC 2328 (v2 for IPv4), RFC 5340 (v3 for IPv6) |
| Algorithm | Dijkstra's SPF (Shortest Path First) |
| Metric | Cost (based on interface bandwidth) |
| Administrative Distance (AD) | 110 |
| Transport | IP protocol number 89 — not TCP or UDP |
| Multicast addresses | 224.0.0.5 (all OSPF routers), 224.0.0.6 (DR/BDR only) |
| Supports VLSM / CIDR | Yes — classless routing protocol |
| Supports IPv6 | Yes — via OSPFv3 |
| Supports hierarchical design | Yes — 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 knows | Complete topology map (LSDB) | Only its neighbour's routing table | Neighbour's metrics + topology table |
| Algorithm | Dijkstra's SPF | Bellman-Ford | DUAL (Diffusing Update Algorithm) |
| Metric | Cost (bandwidth-based) | Hop count (max 15) | Composite (bandwidth + delay + load + reliability) |
| Updates | Triggered; full LSA refresh every 30 min | Periodic (every 30 s); full table | Triggered; partial updates only |
| Convergence speed | Fast | Slow (counting to infinity problem) | Very fast (DUAL guarantees loop-free backup) |
| Scalability | High — scales with multi-area design | Low — 15-hop maximum limit | High — supports large networks |
| Loop prevention | SPF on identical LSDB guarantees loop-free paths | Split horizon, route poisoning | DUAL feasibility condition |
| Open standard | Yes | Yes | Partially (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)
| Priority | Source | Notes |
|---|---|---|
| 1 (highest) | Manually configured with router-id command | Best practice — always configure this explicitly |
| 2 | Highest IP address on a loopback interface | Loopbacks never go down — more stable than physical interfaces |
| 3 (fallback) | Highest IP address on any active physical interface at OSPF start-up | Risky — 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
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 Field | Must Match? | Notes |
|---|---|---|
| Area ID | ✅ Yes | Both interfaces must be in the same OSPF area |
| Hello interval | ✅ Yes | Default 10 s (broadcast/P2P), 30 s (NBMA) |
| Dead interval | ✅ Yes | Default 4 × hello interval (40 s on broadcast) |
| Subnet mask | ✅ Yes (broadcast) | Not checked on point-to-point links |
| Area type (stub flag) | ✅ Yes | Both must agree on stub/NSSA; mismatch blocks adjacency |
| Authentication | ✅ Yes | Type and key must match if configured |
| Router ID | Must be unique | Duplicate RIDs cause routing problems throughout the domain |
| MTU | ⚠️ Should match | MTU 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
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.
| Role | Function | Adjacency Behaviour |
|---|---|---|
| DR | Collects and re-floods LSAs for the entire segment. Generates the Type 2 Network LSA. | Full adjacency with ALL routers on the segment |
| BDR | Listens passively to all exchanges; takes over instantly if the DR fails. | Full adjacency with ALL routers on the segment |
| DROther | All 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
| Priority | Criterion | Notes |
|---|---|---|
| 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 ID | Used 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)..."
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 Concept | Key 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 routes | Routes within the same area — shown as O in the routing table |
| Inter-area routes | Routes between areas via ABR — shown as O IA |
| External routes | Routes 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 type | Link-state | Advanced distance-vector | Distance-vector |
| Standard | Open — RFC 2328 | Cisco (RFC 7868 partial) | Open — RFC 2453 |
| Algorithm | Dijkstra SPF | DUAL | Bellman-Ford |
| Metric | Cost (bandwidth) | Composite (BW + delay + …) | Hop count |
| AD | 110 | 90 internal / 170 external | 120 |
| Max hop count | None (area-based scalability) | 100 default / 255 max | 15 hops (16 = unreachable) |
| Supports VLSM | Yes | Yes | Yes (v2 only) |
| Supports IPv6 | Yes — OSPFv3 | Yes — EIGRPv6 | Yes — RIPng |
| Convergence | Fast | Very fast | Slow |
| Scalability | High — multi-area design | High | Low |
| Transport | IP protocol 89 (multicast) | IP protocol 88 (multicast/unicast) | UDP port 520 |
| Best used when | Multi-vendor enterprise or SP networks | Cisco-only enterprise networks | Very small or lab networks only |
12. Common OSPF Problems and Fixes
| Symptom | Likely Cause | Fix / 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
| Topic | Key Facts |
|---|---|
| What is OSPF | Open-standard link-state IGP (RFC 2328 v2, RFC 5340 v3); uses IP protocol 89; classless |
| Algorithm | Dijkstra's SPF runs on an identical LSDB — guarantees loop-free paths |
| Metric | Cost = Reference BW / Interface BW; lower = preferred; increase reference BW for GigE+ networks |
| AD | 110 — preferred over RIP (120); less trusted than EIGRP internal (90) or static routes (1) |
| Router ID | Manual > Highest Loopback IP > Highest Physical IP; must be unique; change requires clear ip ospf process |
| Hello interval | 10 s on broadcast/P2P; 30 s on NBMA — must match on both sides for adjacency |
| Dead interval | 4 × hello interval (40 s default on broadcast) — must match on both sides |
| 5 Packet types | Hello (discover), DBD (compare), LSR (request), LSU (deliver), LSAck (acknowledge) |
| DR/BDR | Elected on broadcast segments; highest priority then highest RID; non-preemptive; DROthers stay 2-Way with each other |
| Multicast | 224.0.0.5 = all OSPF routers; 224.0.0.6 = DR and BDR only |
| Areas | Area 0 is mandatory backbone; ABRs connect areas; LSA flooding confined per area; reduces SPF scope |
| Route codes | O = intra-area; O IA = inter-area; O E1/E2 = external (redistributed from outside OSPF) |
| LSA refresh | Every 30 minutes (LSRefreshTime); MaxAge = 60 minutes; sequence numbers prevent stale data |