Free tech learning for everyone, from basics to pro

Routing & SwitchingNetworking SecurityIntermediate

OSPF fundamentals: link-state routing, areas, cost and basic configuration

In short: OSPF is the most widely used open-standard interior routing protocol. Routers flood link-state advertisements so that each one holds the same map of its area, then run the shortest-path-first algorithm to pick routes with the lowest total cost. Areas, built around backbone area 0, keep large networks scalable.

What OSPF is

Open Shortest Path First (OSPF) is a link-state interior gateway protocol defined by the IETF (OSPFv2 for IPv4 in RFC 2328, OSPFv3 for IPv6). It runs directly over IP as protocol 89 and is supported by virtually every enterprise router, Layer 3 switch and firewall, which makes it the default choice for multi-vendor networks. Its administrative distance on Cisco devices is 110.

Distance-vector protocols only hear "network X is N hops away" from neighbours. Link-state routers instead learn the whole topology of their area, like having the full map instead of directions from a stranger. That lets them calculate loop-free paths and react quickly to changes.

Neighbours, LSAs and SPF

How OSPF builds routesHellosfindneighboursAdjacencysyncdatabasesFlood LSAsshare linksLSDBsame mapeverywhereSPFbest pathsRoutingtableinstallroutes
Figure 1. OSPF routers discover neighbours, exchange link-state advertisements until every router in the area holds the same database, then each runs the SPF algorithm to calculate its own best routes.
  1. Routers send hello packets to 224.0.0.5 on OSPF-enabled interfaces to find neighbours.
  2. Neighbours that agree on key settings form an adjacency and exchange their databases.
  3. Each router describes its links in link-state advertisements (LSAs), which are flooded through the area.
  4. Every router in an area ends up with an identical link-state database (LSDB).
  5. Each router runs Dijkstra's SPF algorithm with itself as the root, and installs the lowest-cost routes.

When a link fails, only an LSA about that change is flooded and SPF reruns, so convergence is typically a few seconds or faster with tuned timers.

Router ID and cost

Each router needs a unique 32-bit router ID, written like an IPv4 address. If you do not set one, the router picks the highest loopback address, then the highest active interface address. Set it explicitly so it never changes unexpectedly.

The OSPF metric is cost: reference bandwidth divided by interface bandwidth, and the route cost is the sum along the path. Cisco's default reference is 100 Mbit/s, which gives Fast Ethernet, 1 Gbit/s and 10 Gbit/s links the same cost of 1. Raise the reference bandwidth on every router (the value is in Mbit/s) so faster links are preferred.

Link speedCost with 100 Mbit/s referenceCost with 100 Gbit/s reference
100 Mbit/s11000
1 Gbit/s1100
10 Gbit/s110
100 Gbit/s11

Areas and router roles

Multi-area OSPFArea 0backboneArea 10branches northArea 20branches southArea 30data centreASBRroutes from outside
Figure 2. In multi-area OSPF every area connects to the backbone, area 0, through an area border router (ABR). An ASBR brings in routes from outside OSPF.

Small networks run a single area, area 0. Large networks split into several areas so that each router keeps a smaller database and changes in one area do not trigger SPF everywhere. Rules and roles:

  • Every area must touch area 0, the backbone; traffic between areas passes through it.
  • An area border router (ABR) has interfaces in area 0 and another area, and can summarise routes between them.
  • An autonomous system boundary router (ASBR) injects external routes, such as a default route or routes from BGP.

Basic configuration

router ospf 1
 router-id 1.1.1.1
 auto-cost reference-bandwidth 100000
 passive-interface default
 no passive-interface GigabitEthernet0/1
 network 10.1.12.0 0.0.0.3 area 0
 network 192.168.10.0 0.0.0.255 area 0
 default-information originate
!
! Alternative: enable OSPF directly on an interface
interface GigabitEthernet0/2
 ip ospf 1 area 0

show ip ospf neighbor
show ip ospf interface brief
show ip route ospf

The network command uses a wildcard mask (try the wildcard calculator) to choose which interfaces join OSPF. Passive-interface default stops hellos on every interface except those you list, so users on LAN ports cannot form an adjacency or inject routes, while the LAN subnets are still advertised.

Real-world example: a campus upgraded its core links to 10 Gbit/s but traffic kept taking an old 1 Gbit/s path. With the default reference bandwidth both links cost 1, so OSPF saw them as equal and the older path had fewer hops. Setting auto-cost reference-bandwidth 100000 on every router fixed path selection immediately.

Practice

What must every OSPF area connect to?
Area 0, the backbone area.
With a reference bandwidth of 10,000 Mbit/s, what is the cost of a 1 Gbit/s interface?
10 (10,000 divided by 1,000).
Why use passive-interface default?
It stops OSPF hellos on all interfaces unless you allow them, so no one can form adjacencies on user ports, while connected networks are still advertised.

Key takeaways

  • OSPF is an open-standard link-state IGP with administrative distance 110.
  • Routers flood LSAs, build identical databases per area, and run SPF to choose routes.
  • Cost is reference bandwidth divided by interface bandwidth; raise the reference on every router.
  • All areas attach to area 0; ABRs join areas and ASBRs bring in external routes.
  • Set a fixed router ID and use passive interfaces on user-facing ports.
Tracks your learning on this device only. See your progress on the learning paths.

About the author

Mohamed Fayas

Founder of FM TecHub. CCNA certified, with a BTEC HND in Network Engineering, and BEng (Hons) in Computer Networking and Cloud Security. He writes practical, plain-English guides on networking, security and cloud.

More about the author

Original content written by Mohamed Fayas for FM TecHub. © 2026 FM TecHub. You're welcome to share a link to this page; please don't copy the text elsewhere without permission.

Stay up to date by email

New notes, tools and security news from FM TecHub, explained simply. Free.

We only use your email to send these updates. See our privacy policy.