Introduction to OSPF: How Link-State Routing Works

OSPF gives every router in an area an identical map and lets each compute its own shortest paths. How the LSDB, adjacencies, DR/BDR, cost, and areas actually fit together, with live captures.

OSPF Basics – Introduction to OSPF: How It Works and Why It Matters - PingLabz OSPF article title card

OSPF (Open Shortest Path First) is the routing protocol running inside most enterprise networks you will ever touch. It is an open standard (RFC 2328 for OSPFv2), it converges fast, it scales through areas, and every serious network vendor implements it. This introduction explains how OSPF actually works, with the concepts in the order you need them and real router output where it helps. It is the starting point for the whole PingLabz OSPF cluster.

The one idea that explains OSPF

OSPF is a link-state protocol, and that phrase carries the entire design. Every OSPF router builds a complete map of the area it lives in: every router, every link, every cost. That map is the link-state database (LSDB), and within an area, every router's copy is identical. Routing decisions are then a local computation: each router runs Dijkstra's shortest path first algorithm over the map, with itself as the root, and installs the results in the routing table.

Contrast that with a distance-vector protocol, where each router only knows what its neighbors tell it ("routing by rumor"). An OSPF router does not trust summaries of the topology; it has the topology. That is why OSPF converges quickly and why loops are rare in a stable area: everyone is computing paths over the same map.

You can see the map directly. Here is the database of a three-router area, captured live:

R1# show ip ospf database

            OSPF Router with ID (1.1.1.1) (Process ID 1)

		Router Link States (Area 0)

Link ID         ADV Router      Age         Seq#       Checksum Link count
1.1.1.1         1.1.1.1         46          0x80000006 0x0062A7 3
2.2.2.2         2.2.2.2         44          0x80000006 0x0028C1 3
3.3.3.3         3.3.3.3         39          0x80000006 0x00721B 3

Three routers, three router LSAs (link-state advertisements). Each router describes its own links; flooding delivers every description to every router; the union of the descriptions is the map.

Neighbors and adjacencies

Before any databases synchronize, routers have to find each other. OSPF routers multicast Hello packets (to 224.0.0.5, IP protocol 89) on every OSPF-enabled interface. Two routers become neighbors when their Hellos agree on the essentials: same area, same subnet, matching Hello and Dead timers, matching authentication.

Being a neighbor is not the same as being adjacent. An adjacency is a fully synchronized database relationship, reached by walking an eight-state machine (Down, Init, 2-Way, ExStart, Exchange, Loading, Full). The state you want to see is FULL:

R1# show ip ospf neighbor

Neighbor ID     Pri   State           Dead Time   Address         Interface
2.2.2.2           1   FULL/DR         00:00:34    10.50.100.3     Ethernet0/1
3.3.3.3           1   FULL/DR         00:00:38    10.50.13.3      Ethernet0/0

And the router logs each adjacency as it completes, which is the fastest way to confirm a change did what you expected:

*Aug 24 00:38:53.134: %OSPF-5-ADJCHG: Process 1, Nbr 2.2.2.2 on Ethernet0/1 from LOADING to FULL, Loading Done

The state machine matters most when it stalls, because each stuck state points at a specific cause. Stuck in ExStart or Exchange is the famous one: the usual culprit is an MTU mismatch, because OSPF carries the interface MTU inside database description packets and refuses to synchronize across a disagreement. (Not DR priorities, whatever older articles claim.) The full walkthrough is in OSPF neighbor states explained.

The DR and BDR

On a multi-access segment (Ethernet), OSPF does not build a full mesh of adjacencies between every pair of routers; with n routers that would be n(n-1)/2 relationships, all flooding to each other. Instead, each segment elects a Designated Router (DR) and a Backup Designated Router (BDR). Everyone forms a full adjacency with the DR and BDR only; the other routers (DROTHERs) stay at 2-Way with each other, which is normal and not a fault.

In the neighbor output above, the "/DR" suffix tells you the neighbor's role on that segment. Note that even a link with just two routers on it elects a DR if the network type is broadcast, which is why lab output on back-to-back Ethernet links shows DR/BDR where you might expect a plain point-to-point adjacency.

Cost: how OSPF picks paths

Every interface has a cost; the cost of a path is the sum of the outgoing interface costs along it; lowest total wins. Cost defaults to reference bandwidth divided by interface bandwidth, and the default reference is 100 Mbps, which makes every modern link cost the same. Raising it is standard practice (consistently, on every router in the domain).

Where two paths tie, OSPF installs both and load-shares. Real routing table, real tie:

R1# show ip route ospf
O        10.50.23.0/24 [110/20] via 10.50.100.3, 00:00:38, Ethernet0/1
                       [110/20] via 10.50.13.3, 00:00:38, Ethernet0/0

Two next hops for one prefix: equal-cost multipath, on by default. The 110 is OSPF's administrative distance; the 20 is the path cost. The deep dive is in OSPF metric and cost calculation.

Areas: why, and when you care

The identical-map guarantee has a price: every topology change inside an area makes every router in the area reflood and recompute. Areas bound that blast radius. Area 0 is the backbone; other areas attach to it through Area Border Routers (ABRs), which summarize between areas. Inside an area you have the full map; between areas you get distances, not topology.

The honest guidance for a modern network: routers handle far bigger areas than the folklore suggests, and a single area 0 is the right design for most enterprises until you have hundreds of routers or a deliberate summarization plan. Learn areas because you will inherit multi-area networks, not because your 40-router campus needs six of them.

The five packet types

Hello
Discover and keep neighbors. Carries the parameters both sides must agree on.
DBD
Database Description: a table of contents of one router's LSDB, exchanged during synchronization. Carries the interface MTU.
LSR
Link-State Request: "send me the full copy of these LSAs I am missing."
LSU
Link-State Update: the LSAs themselves, both during sync and during flooding.
LSAck
Acknowledgment. Flooding is reliable; every LSA is confirmed.

What "converged" actually means

A network is converged when every router's LSDB is synchronized and every router has finished SPF over it. In practice you verify convergence with three commands, in this order: show ip ospf neighbor (everything FULL or legitimately 2-Way), show ip ospf database (same LSA counts everywhere), show ip route ospf (the prefixes you expect, with the next hops you expect). If those three agree with your mental model of the network, OSPF is doing its job.

Why OSPF, over the alternatives

Against EIGRP: OSPF is an open standard, so it survives vendor mixing and acquisitions; EIGRP's stronghold is Cisco-only shops. Against IS-IS: functionally similar, but OSPF expertise is far easier to hire for outside service providers. Against BGP: different job entirely; BGP is policy and scale between networks, OSPF is fast topology tracking within one. Most real networks run OSPF inside and BGP at the edges, and the pairing is covered in BGP vs OSPF.

Key takeaways

OSPF gives every router in an area an identical map and lets each router compute its own shortest paths over it. Neighbors form through Hellos; adjacencies are synchronized databases; FULL is the healthy state, and each stuck state names its own cause (ExStart means check MTU first). DR/BDR keeps multi-access segments efficient. Cost is the only metric, ties produce ECMP, and the reference bandwidth default needs raising. Areas bound flooding, and area 0 alone is a legitimate design at enterprise scale.

From here: configure OSPF step by step on real routers, keep the OSPF cheat sheet within reach, and use the OSPF complete guide as the map of the whole cluster.

Read next