What is OSPF?
OSPF is a routing protocol used inside one organisation's network, like a company, campus or internet provider. Every router describes its own links in link-state advertisements and floods them to the others, so all routers end up with the same map. Each then works out the shortest path to every network with Dijkstra's algorithm.
Because every router has the full map, OSPF reacts quickly when a link fails: the news floods out and traffic moves to the next best path, often in under a second. It runs directly on IP as protocol 89.
Think of it like this. OSPF is like every driver in a city sharing a live road map. When one road closes, the driver who sees it tells their neighbours, who tell theirs, until everyone has the same updated map. Each driver then works out their own fastest route from it.
Step by step
Normal
4 stepsThree routers say hello, elect a designated router, copy the link-state database and compute shortest paths.
Normal
4 stepsThree routers say hello, elect a designated router, copy the link-state database and compute shortest paths.
- 1
Hello
Every 10 seconds to 224.0.0.5
Each router multicasts a Hello on the LAN. It lists the neighbours it has heard. When R1 sees its own ID in R3's list, they have two-way contact.
- 2
DR election
Highest priority, then highest ID
On a shared LAN, routers elect a designated router (DR) and a backup (BDR), so each router syncs with two routers instead of all of them. All priorities are 1, so the highest router ID wins: R3 is DR and R2 is BDR. The election is not pre-emptive: a better router joining later does not take over.
- 3
Database exchange
DBD, LS Request, LS Update
R1 sends summaries of the link-state advertisements (LSAs) it has. The DR sends its own list. R1 asks for anything it is missing, and the DR sends the full LSAs.
- 4
Full and SPF
Same map everywhere
R1 acknowledges the LSAs. Its database now matches the DR's, so the neighbour state is Full. Every router runs the shortest path first (Dijkstra) calculation on the same map and fills its routing table.
Link fails
4 stepsA cable between R2 and R4 is cut. The routers flood the news, rerun SPF and move traffic to the backup path.
Link fails
4 stepsA cable between R2 and R4 is cut. The routers flood the news, rerun SPF and move traffic to the backup path.
- 1
Best path
R1, R2, R4: cost 20
Every link costs 10 except R3 to R4, which is a slower line set to cost 30. Traffic from the branch to the office server goes via R2, total cost 20.
- 2
Cable cut
R2 and R4 both notice
The fibre between R2 and R4 is cut. Both routers see the link go down at once and write new Router LSAs without it, with a higher sequence number.
- 3
Flooding
LS Update, LS Acknowledge
Each router sends its new LSA to its neighbours, who acknowledge it and pass it on. Within a fraction of a second every router has the same updated map.
- 4
SPF again
New path via R3, cost 40
Every router reruns the shortest path calculation. R1 now sends office traffic via R3. If the link had stayed up but R2 had silently died, R1 would only notice after the 40-second dead interval, which is why many networks add BFD for fast detection.
Timer mismatch
3 stepsA new router uses different hello timers. Both keep saying hello, and neither ever becomes a neighbour.
Timer mismatch
3 stepsA new router uses different hello timers. Both keep saying hello, and neither ever becomes a neighbour.
- 1
Different timers
10 and 40 versus 5 and 20
Kenji adds a new router with hello every 5 seconds and a dead interval of 20. The old router uses the defaults, 10 and 40.
- 2
Hellos ignored
Values must match exactly
Each router checks the hello interval, dead interval, network mask, area and options in every Hello. If any differ, it drops the Hello and logs a mismatch.
- 3
No adjacency
Stuck before Init
Neither router ever lists the other as a neighbour, so no database is shared and no routes are learned. Fix: set the same timers on both. A mismatched MTU causes a similar fault later, stuck at ExStart.
Myths and mix-ups
- OSPF does not run over TCP or UDP; it is IP protocol 89.
- OSPF does not count hops; it adds up link costs, so three fast links can beat one slow one.
- OSPF is not for routing between internet providers; that is BGP's job.
- The designated router is not the most important router in the network; it only coordinates one shared LAN segment.
- A higher-priority router joining later does not take over as DR; the election is not pre-emptive.
Try it yourself
Run these on your own computer to see OSPF at work.
See your own routing table (Windows)
route printYour PC does not run OSPF, but this is the kind of table OSPF fills on a router.
See your own routing table (macOS)
netstat -rnThe default line points at your router. OSPF routers hold thousands of lines like these.
See your own routing table (Linux)
ip routeOn a Linux router running an OSPF daemon, its routes show up here marked proto ospf.
Watch for OSPF on a network (macOS or Linux)
sudo tcpdump -n -i any proto ospfOn an office network that runs OSPF, you may see Hello packets to 224.0.0.5 every 10 seconds.
OSPF at a glance
- Layer
- Network (3)
- IP protocol number
- 89
- Multicast groups
- 224.0.0.5 all OSPF routers, 224.0.0.6 DR and BDR
- Default timers
- Hello 10 s, dead 40 s on Ethernet
- Algorithm
- Link state, Dijkstra shortest path first
- Metric
- Cost, often from link speed
- Defined in
- RFC 2328 (OSPFv2, 1998); OSPFv3 for IPv6 in RFC 5340
Defined inRFC 2328RFC 5340
Header fields
What OSPF puts in its messages, with example values from the stories above.
OSPFv2
- Version
2- Message type
1 (Hello)- Packet length
44 bytes- Router ID
10.0.0.1A 32-bit name for the router, written like an IP address.- Area ID
0.0.0.0 (backbone)Neighbours must be in the same area. Area 0 is the backbone every other area connects to.- Checksum
verified- Auth type
0 (none)- Network mask
255.255.255.0- Hello interval
10 secondsHow often this router says hello. Neighbours must use the same value.- Options
E (external routes allowed)
Test yourself
What does OSPF use to pick the best path?
Questions people ask
What is OSPF used for?
Finding the best paths between routers inside one organisation's network. It keeps every router's map identical and reroutes quickly when a link fails.
What is the difference between OSPF and BGP?
OSPF works inside one network and picks the lowest-cost path. BGP works between separate networks and picks paths by policy. Providers use both: OSPF inside, BGP at the edges.
What is a designated router in OSPF?
On a shared LAN, one router is elected to collect and share link-state updates, with a backup ready to take over. It saves every router from syncing with every other router.
Why is my OSPF neighbour stuck in ExStart?
Most often the interface MTU differs on the two sides, so the database description packets are rejected. Make the MTU match.
How fast does OSPF converge?
When a link goes down, routers flood the change and rerun SPF within milliseconds to a second or so. If a neighbour dies silently, detection waits for the dead interval, 40 seconds by default, unless BFD is used.