OSPF Explained: How Routers Find the Best Path
OSPF (Open Shortest Path First) is a link-state interior gateway protocol that routers use to learn the best path through a network. Each router builds a complete map of the area, then runs the shortest-path (Dijkstra) algorithm to pick the lowest-cost route.
How OSPF works, step by step
- Routers send Hello packets to discover neighbours on a link.
- Neighbours form adjacencies and exchange link-state information.
- Each router stores this in a link-state database (LSDB) — an identical map of the area.
- Each router runs the SPF (Dijkstra) algorithm to build a shortest-path tree.
- The best routes are installed into the routing table.
OSPF LSA types (overview)
| Type | Name | Purpose |
|---|---|---|
| 1 | Router LSA | Router's own links within an area |
| 2 | Network LSA | Multi-access segment, from the DR |
| 3 | Summary LSA | Routes between areas, from the ABR |
| 5 | External LSA | Routes redistributed from outside OSPF |
Areas and router roles
OSPF uses areas to keep large networks scalable. Area 0 is the backbone; all other areas connect to it. An ABR (Area Border Router) sits between areas, and an ASBR connects OSPF to other routing domains.
Cost / metric
OSPF chooses paths by cost, calculated from interface bandwidth (reference bandwidth / interface bandwidth). The total cost of a path is the sum of the costs of outgoing interfaces — the lowest total wins.
Where you'll use it
OSPF is one of the most widely deployed enterprise routing protocols. You'll configure it hands-on in our CCNA and master multi-area design in CCNP. Compare it with BGP, the protocol that runs the internet.
Frequently asked questions
Is OSPF in the CCNA exam?
Yes. CCNA covers OSPFv2 single-area configuration and concepts. CCNP goes much deeper into multi-area OSPF.
What algorithm does OSPF use?
OSPF uses Dijkstra's shortest-path-first (SPF) algorithm to calculate the lowest-cost path to each destination.
What is OSPF cost based on?
By default OSPF cost is based on interface bandwidth — higher bandwidth means lower cost and a more preferred path.
Related articles
Want hands-on training?
Learn this on real Cisco lab devices with placement support at Attila Technologies, Ahmedabad.