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
- Routers send hello packets to 224.0.0.5 on OSPF-enabled interfaces to find neighbours.
- Neighbours that agree on key settings form an adjacency and exchange their databases.
- Each router describes its links in link-state advertisements (LSAs), which are flooded through the area.
- Every router in an area ends up with an identical link-state database (LSDB).
- 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 speed | Cost with 100 Mbit/s reference | Cost with 100 Gbit/s reference |
|---|---|---|
| 100 Mbit/s | 1 | 1000 |
| 1 Gbit/s | 1 | 100 |
| 10 Gbit/s | 1 | 10 |
| 100 Gbit/s | 1 | 1 |
Areas and router roles
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?
With a reference bandwidth of 10,000 Mbit/s, what is the cost of a 1 Gbit/s interface?
Why use passive-interface default?
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.
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.