11011110R2R4R1R3R5
Envelopes: Hellos and data packetsYellow tiles: map pieces (LSAs) · slots on top: each router's mapCables with cost badges · blue: R1's shortest-path treeCoral cross: a failed link · dashed line: area 0OSPF is a link-state routing protocol: routers meet their neighbours with Hellos, flood a description of their own links so every router holds the same map, then each runs Dijkstra's shortest-path-first algorithm on it. Here R1's cheapest path to R5 is R1 → R2 → R3 → R5 at cost 3, not the two-hop path at cost 11; when R2–R3 fails, the new map gives R1 → R3 → R5 at cost 11. SPF is Dijkstra's 1959 shortest-path algorithm (RFC 2328 §16.1). A link only counts if the routers at both ends list it, so one stale piece cannot keep a dead link alive. When two paths tie, OSPF can keep both (equal-cost multipath); this network has no ties.

Meet the neighbours

  1. Every 10 seconds, each router sends a small Hello out of every link to say "I am here". R1 says hello to R2 and R3, the routers at the other end of its two links. OSPF stands for Open Shortest Path First.

Build the map

Shortest path first

When a link fails

What is happening

;; step 1/12 · hello
;; r1 → r2
packet     Hello (OSPF type 1), IP protocol 89
from       R1, Router ID 192.0.2.1
to         224.0.0.5 (all OSPF routers)
area       0.0.0.0
every      10 s · dead after 40 s
out of     R1–R2 and R1–R3

OSPF version 2 (RFC 2328) routes IPv4; OSPFv3 (RFC 5340) does the same for IPv6. OSPF packets ride directly on IP as protocol 89. Hellos go to 224.0.0.5; HelloInterval 10 s and RouterDeadInterval 40 s are the RFC's sample values for a LAN and the usual defaults. Neighbours must agree on the area and on both timers. RFC 2328 leaves each interface's cost (1 to 65535) to the operator. Cost = 100 Mb/s ÷ bandwidth, at least 1, is the long-standing default in common router software. With that reference, 1 Gb/s and 10 Gb/s links also get cost 1, so operators often raise the reference bandwidth.