What Is OSPF and How Does It Work?
OSPF (Open Shortest Path First) is a link-state interior gateway protocol (IGP) — a routing protocol that runs inside a single organization's network and lets routers automatically discover the best path to every subnet without anyone programming each route by hand. Every OSPF router learns a complete map of the network, then independently runs a shortest-path calculation to decide how to reach each destination, so the whole network settles on a consistent, loop-free set of routes and adapts on its own when a link goes up or down.
Part of the OSPF learning hub
What OSPF Actually Is
OSPF is one of the most widely deployed routing protocols in enterprise networks, which is why it's a cornerstone of the CCNA. The phrase "interior gateway protocol" means it's designed to run within one administrative domain — a company, a campus, a data center — rather than between different organizations across the public internet, which is BGP's job.
"Link-state" describes how it works. Instead of trusting secondhand summaries from its neighbors about distant networks, each router builds its own detailed map of the topology and calculates routes from that map. OSPF is also an open standard rather than a single vendor's protocol, so it shows up in mixed-vendor networks everywhere.
The Problem It Solves: Static vs. Dynamic Routing
With static routing, an administrator manually types every route into every router. That's perfectly fine for a handful of devices, but it doesn't scale and it doesn't heal: if a link fails, the static route keeps pointing at the dead path until a human fixes it, and adding one new subnet can mean editing many routers.
Dynamic routing protocols like OSPF solve both problems. Routers advertise the networks they know about, automatically recalculate when the topology changes (a process called convergence), and steer traffic around failures on their own. The trade-off is more protocol overhead and a bit more complexity — but for anything beyond a small, unchanging network, that's a bargain.
How It Works: Neighbors, LSAs, and the Link-State Database
Before OSPF exchanges any routing information, routers have to find each other. Each OSPF-enabled interface periodically sends small Hello packets; when two routers hear each other's Hellos and agree on key parameters (such as the area, the timers, and the subnet), they become neighbors and, in most cases, form an adjacency — the relationship over which they will actually trade routing data.
Adjacent routers then flood Link-State Advertisements (LSAs) — compact records that describe a router's links, their addresses, and their cost. Every router stores the LSAs it receives in a link-state database (LSDB). Because those LSAs are flooded to everyone in the area, all routers in the area end up with an identical database: the same complete map of the topology. Picture every router in a city receiving the exact same road atlas.
SPF and Cost: Choosing the Best Path
Once a router holds the full map, it runs the Dijkstra Shortest Path First (SPF) algorithm — placing itself at the root and computing the lowest-total-cost path to every destination. Those results become the OSPF routes installed in the routing table.
OSPF's metric is cost, and cost is derived from interface bandwidth: faster links carry lower cost, so OSPF naturally prefers them. Importantly, it adds up the cost of every link along a path rather than simply counting hops the way older protocols like RIP did, so a route with more routers but much faster links can win. (By default OSPF's reference treats anything at or above 100 Mbps as cost 1, so real networks often raise that reference so gigabit and faster links get distinct costs — a knob your configuration guide covers.)
Areas and the Backbone
In a large network, having every router recompute the entire topology gets expensive. OSPF scales through areas, which divide the network into smaller regions. Routers inside an area share full detail with each other but only summarized reachability with the rest of the network, keeping each router's database and SPF calculation smaller.
Every OSPF network has a backbone area, called area 0, and all other areas must connect to it. A router sitting on the border between an area and the backbone is an Area Border Router (ABR), and it passes summarized routes between them. If a network only needs one area, that single area should be area 0 — the rule of thumb is simply that everything touches the backbone.
DR/BDR and Common Beginner Gotchas
On a shared multi-access segment — an Ethernet LAN with several routers on it — every router forming a full adjacency with every other router would create a storm of redundant LSA flooding. To prevent that, OSPF elects a Designated Router (DR) and a Backup DR (BDR); the other routers form full adjacencies only with the DR and BDR, which relay updates to everyone. Election favors the highest OSPF priority, with the highest router ID as the tiebreaker. Point-to-point links have only two routers, so no DR is needed.
A few things reliably trip up beginners. The DR is not a "primary router" that all traffic flows through — it only optimizes flooding; forwarding still follows each router's own SPF result. DR election is also not preemptive, so a higher-priority router that joins later does not bump an existing DR. And the router ID — a 32-bit value that looks like an IP and is usually taken from a loopback interface (which OSPF advertises as a /32 host route) — identifies the router but need not be a routable path; pinning it to a stable loopback keeps it from changing unexpectedly.
Frequently asked questions
What's the difference between OSPF and a static route?
A static route is a single path you type in by hand; it never changes on its own, so if that path fails, traffic keeps trying to use it until someone intervenes. OSPF learns routes automatically from other routers, recalculates when the topology changes, and reroutes around failures with no human help. Static routes stay handy for small or special-case paths, but OSPF earns its keep as soon as a network has enough routers and links that maintaining routes by hand becomes slow and error-prone.
Why does OSPF use "cost" instead of just counting hops?
Hop count treats every link as equal, so it would happily send traffic across three slow links rather than four fast ones. OSPF's cost is based on bandwidth — faster interfaces have lower cost — and it sums the cost along the entire path, so it prefers routes that are genuinely faster end to end, not merely shorter in router count. This is a core reason link-state protocols like OSPF make smarter path decisions than older distance-vector protocols like RIP.
Does OSPF run on the public internet between different companies?
No. OSPF is an interior gateway protocol, meaning it's built to run within a single organization's network. Routing between separate organizations across the internet is handled by BGP, an exterior gateway protocol. On the CCNA you'll use OSPF for the inside of a campus or enterprise and treat what happens between autonomous systems as BGP's territory.
Now build it on real Cisco IOS
Concepts stick when you configure them. Try a free graded lab, then grade your own config against the answer key.