A link goes down in your corporate network at 2 AM. Within two seconds, every router in the building has recalculated its routing table and traffic is flowing through an alternate path. Nobody wakes up. Nobody notices. That's OSPF working the way it was designed. Understanding how it does that — and what breaks when it doesn't — is essential for anyone who works with enterprise networks.
TL;DR
- OSPF builds a complete map of your network topology, then calculates the best path to every destination
- Every router in the same area has an identical database — no hop-by-hop guessing like RIP
- Uses Dijkstra's algorithm (SPF) to find lowest-cost paths based on link bandwidth
- Areas limit flooding overhead — Area 0 is the backbone that everything connects through
- Converges in under 2 seconds with BFD; without it, the Dead timer adds 40 seconds of detection delay
What Is OSPF and What Problem Does It Solve?
When you have a network with dozens of routers — like in a corporate office, a university campus, or a data center — every router needs to know where to send traffic. If Router A wants to send a packet to a server three hops away, it needs to know which direction to send it. And when a link fails, every router needs to update its view of the network and find a new path quickly.
OSPF — Open Shortest Path First — is the protocol that handles this inside a single organization's network. It's an interior gateway protocol (IGP), meaning it's designed to work within one administrative domain. While BGP connects different organizations across the internet, OSPF connects routers inside a single company or campus.
OSPF was first defined in RFC 1131 in 1989 and has been updated several times since. OSPFv2 (RFC 2328) is the version used for IPv4 networks. OSPFv3 adds IPv6 support. It's open standard — unlike Cisco's proprietary EIGRP — which means it works across routers from different vendors.
The Core Idea: Link State Routing
OSPF uses a concept called link state routing. Each router doesn't just know about its directly connected neighbors — it builds a complete map of the entire network topology. Every router ends up with an identical view of the network, and each independently calculates the best path to every destination using that map.
Compare this to distance-vector protocols like RIP, where each router only knows what its neighbors tell it and forwards routing updates hop by hop. OSPF's link-state approach is more complex to implement but converges faster, scales better, and has no hop-count limitation.
How OSPF Builds the Network Map
The process happens in stages:
Stage 1: Neighbor Discovery
OSPF routers send Hello packets out of each OSPF-enabled interface every 10 seconds (on broadcast networks). When two routers on the same network segment receive each other's Hellos and agree on key parameters (area ID, timers, authentication), they form an adjacency — they become OSPF neighbors.
Stage 2: LSA Flooding
Once neighbors are established, each router generates a Link State Advertisement (LSA) describing its directly connected links — which interfaces it has, what networks they connect to, and the cost of each link. These LSAs are flooded to all routers in the OSPF area.
Every router stores all received LSAs in its Link State Database (LSDB). When the flooding is complete, all routers in the same area have identical LSDBs — an identical picture of the network.
Stage 3: SPF Calculation
Each router runs Dijkstra's Shortest Path First (SPF) algorithm on its LSDB to calculate the shortest path tree — the optimal route to every destination in the network. The result populates the router's routing table.
When anything changes — a link goes down, a new router comes online — the affected router generates a new LSA, floods it to its neighbors, and every router runs SPF again. This convergence typically happens in under a second in well-tuned networks.
OSPF Cost: How Routes Are Compared
OSPF uses cost as its metric. Cost is calculated as:
Cost = Reference Bandwidth / Interface Bandwidth
The reference bandwidth is 100 Mbps by default on Cisco routers (though you can change this). So a 100 Mbps Ethernet interface has cost 1, a 10 Mbps interface has cost 10, and a 1 Gbps interface also has cost 1 (which is why you should update the reference bandwidth on modern networks).
The total cost of a path is the sum of costs on all outbound interfaces along the route. OSPF prefers the path with the lowest total cost. Two paths with equal cost trigger ECMP (Equal-Cost Multi-Path) — OSPF will load-balance traffic across both.
OSPF Areas: Scaling the Protocol
In very large networks, having every router flood LSAs to every other router would create massive overhead. OSPF addresses this with areas.
An OSPF area is a group of routers that share a complete LSDB with each other. Area 0 is the backbone area — all other areas must connect to it. Routers on the border between two areas are called Area Border Routers (ABRs).
Within an area, routers exchange full LSA detail. Between areas, ABRs summarize routes before advertising them into other areas. This dramatically reduces LSA flooding overhead in large networks and lets OSPF scale to networks with hundreds or thousands of routers.
Common area design:
- Area 0 (backbone) — connects all other areas, typically contains the core/distribution layer routers
- Standard areas — contain access layer routers, connected to Area 0 via ABRs
- Stub areas — areas that don't receive external routes, only a default route from the ABR, reducing routing table size
- Totally stubby areas — even more restricted, only receive a default route, good for branch offices with simple connectivity
DR and BDR Election on Broadcast Networks
On networks where multiple OSPF routers share the same broadcast segment (like a VLAN), every router forming full adjacency with every other router would create O(n squared) adjacencies. OSPF solves this by electing a Designated Router (DR) and Backup Designated Router (BDR).
All other routers (called DROthers) only form full adjacency with the DR and BDR. LSAs are sent to the DR, which then distributes them to all others. This reduces the number of adjacencies from n(n-1)/2 to just 2(n-2)+1.
DR election is based on OSPF priority (higher wins) and then Router ID (higher wins). Priority 0 means a router is ineligible to be DR or BDR.
OSPF vs BGP: The Key Differences
| Feature | OSPF | BGP |
|---|---|---|
| Type | Interior Gateway Protocol | Exterior Gateway Protocol |
| Scope | Within one AS/organization | Between different organizations |
| Algorithm | Dijkstra (SPF) | Path vector / policy-based |
| Metric | Cost (bandwidth-based) | AS_PATH, LOCAL_PREF, MED |
| Convergence | Very fast (sub-second) | Slow (seconds to minutes) |
| Policy control | Limited | Extremely granular |
| Route table size | Limited by area design | Handles full internet routing table |
| Complexity | Moderate | High |
OSPF vs EIGRP: What's the Practical Difference?
EIGRP is Cisco's proprietary alternative to OSPF. It's easier to configure, uses a different metric calculation (bandwidth + delay), and converges fast using DUAL (Diffusing Update Algorithm). The main limitation: EIGRP only works on Cisco gear. OSPF works on any vendor's equipment.
If your network is 100% Cisco, EIGRP is a reasonable choice. Mixed-vendor environments need OSPF. And since most enterprise networks have at least some non-Cisco gear, OSPF tends to win out in practice.
Common OSPF Problems and Fixes
Neighbors Won't Establish
The most common cause is a mismatch in Hello or Dead timers, area ID, authentication settings, or subnet mask. OSPF requires all these to match between neighbors. Run show ip ospf neighbor to see neighbor state and debug ip ospf adj to see what's failing.
Routes Missing from Routing Table
Check if the network is in the LSDB (show ip ospf database) but not in the routing table. If it's in the LSDB, the SPF calculation might be excluding it due to cost or there may be a summarization issue at an ABR.
Suboptimal Routing
If OSPF is choosing a slower path than expected, check the interface costs. On modern gigabit or 10G networks, the default reference bandwidth of 100 Mbps means all these interfaces get cost 1 — OSPF can't differentiate between them. Update with auto-cost reference-bandwidth 10000 for 10G networks.
OSPF Neighbor Stuck in EXSTART or EXCHANGE
An MTU mismatch is the most common cause. OSPF checks MTU during the Database Description exchange. If the MTUs don't match, one side rejects the DD packets. Fix by either matching the MTU on both interfaces or using ip ospf mtu-ignore to skip the check.
Pro Tips for OSPF
- Always set
passive-interface defaultand then explicitly enable OSPF only on interfaces that need it. This prevents OSPF from trying to form neighbors on end-user-facing interfaces and reduces unnecessary Hello traffic. - Use loopback interfaces as OSPF Router IDs. Loopbacks are always up, so the Router ID stays stable even if physical interfaces go down.
- In multi-area designs, summarize routes at ABRs. Summarization reduces LSA volume and makes the network more resilient to individual link flaps.
- On point-to-point links, set the OSPF network type to
point-to-pointto skip DR/BDR election and form a direct adjacency faster. - Set OSPF priority to 0 on routers you never want to become DR. On busy backbone routers, being DR adds unnecessary load.
- Enable BFD (Bidirectional Forwarding Detection) alongside OSPF on critical links. BFD can detect link failure in milliseconds, triggering OSPF reconvergence far faster than waiting for the 40-second Dead timer.
Check your IP and routing details to see what your network is advertising publicly