OSPF (Open Shortest Path First) is a link-state interior gateway protocol in which every router builds an identical map of the network and computes the shortest path to each destination with Dijkstra’s algorithm. In routing, OSPF is the most widely used open standard for dynamic routing inside one organization’s network, from campus cores to data centers and service provider backbones.
OSPF version 2 for IPv4 is defined in RFC 2328, and OSPFv3 in RFC 5340 extends the protocol to IPv6. Unlike BGP, which exchanges routes between autonomous systems, OSPF is designed for fast, automatic convergence within a single administrative domain.
How OSPF builds and uses its link-state database
OSPF routers first discover neighbors by sending Hello packets to the multicast address 224.0.0.5, directly over IP protocol number 89. Neighbors that agree on key parameters form an adjacency and synchronize their link-state databases (LSDB), which describe every router, link and cost in the area.
Each router then runs the shortest path first (SPF) calculation, placing itself at the root of a tree and finding the lowest total cost to every prefix. The best results are installed in the routing table. When a link changes, the affected router floods a link-state advertisement (LSA), and all routers recalculate.
Because every router in an area holds the same database, OSPF avoids the routing loops and slow counting behavior of older distance-vector protocols such as RIP. The price is memory and processor time for the database and the SPF runs, which is why implementations apply SPF throttling timers that delay recalculation briefly when many changes arrive at once.
Adjacency formation passes through defined neighbor states, which are the first place to look when two routers fail to exchange routes.
| State | What has happened | Stuck here usually means |
|---|---|---|
| Down / Init | Hello sent or received one way | Filtering, mismatched area or subnet |
| 2-Way | Bidirectional Hellos seen | Normal between non-DR routers |
| ExStart / Exchange | Master chosen, database summaries swapped | MTU mismatch |
| Loading | Missing LSAs requested | Corrupt or very large LSDB |
| Full | Databases synchronized | Healthy adjacency |
Areas, router roles and LSA types
OSPF scales through hierarchical areas. All areas must connect to the backbone, area 0, and routers that join areas are area border routers (ABRs), which summarize routes between areas so that a change in one area does not trigger SPF everywhere.
On broadcast segments such as Ethernet, routers elect a designated router (DR) and a backup, which reduces the number of full adjacencies. Routers that inject external routes, for example from BGP or static routes, are autonomous system boundary routers (ASBRs).
| LSA type | Originated by | Describes | Flooding scope |
|---|---|---|---|
| 1 Router | Every router | Its links and costs | One area |
| 2 Network | Designated router | Routers on a shared segment | One area |
| 3 Summary | ABR | Prefixes from other areas | One area |
| 4 ASBR summary | ABR | How to reach an ASBR | One area |
| 5 External | ASBR | Routes from outside OSPF | Whole domain |
| 7 NSSA external | ASBR in an NSSA | External routes in an NSSA | One NSSA area |
Special area types limit what is flooded into small sites. Stub areas block type 5 LSAs, a stricter stub variant also blocks most type 3 LSAs and leaves only a default route, and not-so-stubby areas (NSSA) allow local external routes while blocking those from elsewhere.
Key OSPF parameters
OSPF behavior is governed by a small set of timers and metrics that must match or be planned consistently across the network.
| Parameter | Typical default | Effect |
|---|---|---|
| Hello interval | 10 s on broadcast links | Neighbor discovery and keepalive |
| Dead interval | 40 s, four Hellos | Time before a neighbor is declared down |
| Reference bandwidth | 100 Mbit/s on many platforms | Basis for automatic cost |
| Interface cost | Reference divided by link speed | Path preference |
| Router priority | 1, range 0 to 255 | DR election, 0 never becomes DR |
| MTU | Must match on both ends | Adjacency reaches Full |
The default reference bandwidth is a classic trap: with 100 Mbit/s, every link of 100 Mbit/s or faster receives cost 1, so a 1 Gbit/s and a 100 Gbit/s link look equal. Operators should raise the reference bandwidth consistently on all routers. Fast failure detection usually comes from BFD rather than from aggressive Hello timers.
OSPF compared with other routing approaches
OSPF is one of several ways to fill a routing table, and the right choice depends on network size, administrative boundaries and required convergence speed.
| Method | Type | Typical use | Main trade-off |
|---|---|---|---|
| Static route | Manual entry | Small networks, default routes | No automatic failover |
| OSPF | Link-state IGP | Enterprise and campus networks | Area design required |
| IS-IS | Link-state IGP | Large provider backbones | Less familiar to many teams |
| EIGRP | Advanced distance-vector | Networks built on one vendor | Limited multi-vendor support |
| BGP | Path-vector EGP | Between autonomous systems | Policy-rich but slower |
A common enterprise pattern combines them: OSPF carries internal prefixes and loopback addresses, while BGP exchanges routes with internet providers and a static or OSPF-originated default route points toward the edge. Keeping the two protocols separated by careful redistribution rules prevents external tables from overwhelming the internal network.
Common OSPF mistakes
Most OSPF incidents come from parameter mismatches and poor area design rather than protocol defects.
- Mismatched timers, area IDs or authentication prevent adjacencies from forming.
- Non-contiguous area 0 splits the backbone and breaks inter-area routing.
- Redistribution without filtering can leak thousands of external routes or create loops.
- Duplicate router IDs cause flapping and inconsistent databases.
- Running OSPF on user-facing interfaces without passive mode exposes the protocol to rogue routers.
Stripped to the essentials
OSPF lets routers share one complete map of the network instead of passing along rumors. Every router knows every road and its length, so each one can work out the quickest route on its own.
When a road closes, the router next to it tells everyone, they all redraw the map and traffic shifts to the next best route within seconds.
Where it is applied
A hospital network connects a main building, two clinics and a data center with redundant fiber links of 10 Gbit/s and older 1 Gbit/s backup links. With static routes, a fiber cut once required manual changes that took most of an hour.
The network team deploys OSPF with the core and data center in area 0 and each clinic in its own area, sets the reference bandwidth to 100 Gbit/s on every router so that 10 Gbit/s links are preferred, and adds BFD for sub-second failure detection.
During a later construction accident that cuts a fiber, OSPF reroutes traffic over the backup link automatically, and clinicians notice no interruption to patient record access.