Networking Tutorials

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

  1. Routers send Hello packets to discover neighbours on a link.
  2. Neighbours form adjacencies and exchange link-state information.
  3. Each router stores this in a link-state database (LSDB) — an identical map of the area.
  4. Each router runs the SPF (Dijkstra) algorithm to build a shortest-path tree.
  5. The best routes are installed into the routing table.

OSPF LSA types (overview)

TypeNamePurpose
1Router LSARouter's own links within an area
2Network LSAMulti-access segment, from the DR
3Summary LSARoutes between areas, from the ABR
5External LSARoutes 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.

VS
Vipul Sir — Lead Instructor, Attila Technologies20+ years in Cisco networking. Teaching CCNA, CCNP, CCIE & CyberOps in Ahmedabad since 2007.

Want hands-on training?

Learn this on real Cisco lab devices with placement support at Attila Technologies, Ahmedabad.

Start your networking career with Attila Technologies

Hands-on Cisco training, real lab devices and placement support in Ahmedabad.