Course menu

Course 9: OSPFLesson 1.2 (2 of 9 in this course)71 of 107 in the CCNA series

What is OSPF?

OSPF in one page: an open-standard link-state protocol, its router ID, areas, cost metric, and where it fits next to RIP, EIGRP and BGP.

Intermediate · 11 min read

What you will learn

After this lesson, you can describe OSPF in your own words, explain how a router chooses its router ID, and follow how LSAs, the LSDB, SPF and cost turn into a route in the routing table.

  • Link-state routing
  • Router ID
  • Areas
  • Cost

OSPF (Open Shortest Path First) is an open-standard, link-state interior routing protocol. Each router describes its own links in link-state advertisements (LSAs), floods them to every router in the area, stores them all in a link-state database (LSDB), and runs the shortest path first (SPF) algorithm on that database to choose the lowest-cost path to every network.

In simple terms: Every router tells all the others what it is connected to. They all end up with the same map, and each one works out its own fastest routes from that map.

A real-life situation

In the previous lesson the routers rerouted around a cut cable by themselves. That raises fair questions. Which router is in charge? How does R1 find out about a cable it isn't connected to? And how does it decide that the top path is better than the bottom one? This lesson answers each of these in turn. Each idea gets its own short section.

OSPF in one paragraph

OSPF is a link-state routing protocol. Each router describes its own links (its interfaces, their subnets, their speed and the neighbours on them) and sends that description to every other router. Every router collects all those descriptions into the same map, and then each router uses the map to work out the best path from its own position to every network. There is no central controller: OSPF is a set of rules that every router follows on its own, and because they follow the same rules with the same map, they reach consistent answers.

OSPF has been an open standard since the early 1990s. Version 2 (OSPFv2, RFC 2328) carries IPv4 routes and is the version this course uses; OSPFv3 was written for IPv6. It runs in enterprise, campus, data centre and service provider networks, and on routers, Layer 3 switches and firewalls from every major vendor.

The OSPF process on one router

On a Cisco router OSPF is off until you start it. Starting it creates an OSPF process: a program running on the router alongside everything else, with a number you choose.

router ospf 1

Global configuration mode. Starts OSPF process 1 (any number from 1 to 65535).

The process ID (the 1 above) only matters inside this router. It isn't sent to other routers, so R1 can use process 1 and R2 process 10 and they still work together. A router can even run two separate OSPF processes, which is why the number exists at all.

The process keeps three tables and uses them in order:

TableWhat is in itShow command
Neighbour tableThe OSPF routers directly connected to this oneshow ip ospf neighbor
Topology table (LSDB)Every LSA in the area: the mapshow ip ospf database
Routing tableThe best path to each network, worked out from the mapshow ip route ospf

The router ID

Before OSPF can send anything, the process needs a name: the router ID (RID). It is a 32-bit number written like an IPv4 address, such as 1.1.1.1, and it must be unique in the OSPF network, because every LSA says which router it came from. When the process starts, the router picks its RID in this order:

  1. The value set with the router-id command under the OSPF process, if there is one.
  2. Otherwise, the highest IPv4 address on a loopback interface that is up.
  3. Otherwise, the highest IPv4 address on any other interface that is up.
router ospf 1 router-id 1.1.1.1

Setting the RID by hand is normal practice: it is predictable and doesn't change when interfaces are added.

If none of the three gives an address (for example, a router with no IPv4 addresses yet), the process can't start, and IOS logs a message like this:

The fix is to configure router-id or give the router a working IPv4 address.
%OSPF-4-NORTRID: OSPF process 1 failed to allocate unique router-id and cannot start

💡 The RID is chosen once, when the process starts. If you change it later, IOS keeps using the old one until you restart the process with clear ip ospf process, which briefly drops every neighbour.

Neighbours: who to talk to

Once it has a RID, the router sends small hello packets out of every interface where OSPF is enabled, every 10 seconds on Ethernet, to the multicast address 224.0.0.5 that every OSPF router listens to. A router on the same link hears them, answers with its own hellos, and the two become neighbours. In the square network, R1 has two neighbours: R2 on Gi0/1 and R3 on Gi0/2. It has no OSPF neighbour towards LAN A, where there are only PCs.

Neighbor ID is the neighbour's router ID; Address is its IP address on the shared link. FULL means their maps are in sync. DR is explained in the DR/BDR lesson.
R1#show ip ospf neighbor
Neighbor ID     Pri   State           Dead Time   Address         Interface
2.2.2.2           1   FULL/DR         00:00:36    10.0.12.2       GigabitEthernet0/1
3.3.3.3           1   FULL/DR         00:00:33    10.0.13.2       GigabitEthernet0/2

Neighbours do two jobs. They let routers find each other without anyone listing them, and they are the path along which the map is shared. The neighbours lesson covers the settings that must match before two routers agree to be neighbours.

Links, link state and LSAs

In OSPF a link is simply a router interface that runs OSPF, and its state is what describes it: its subnet and mask, its cost, its network type, and which neighbours are on it. Each router puts the state of its links into a link-state advertisement (LSA). In simplified form, R4's LSA says:

R4 (RID 4.4.4.4) has a link…SubnetCostNeighbour on it
Gi0/0, to LAN B192.168.4.0/241none
Gi0/1, to R210.0.24.0/3012.2.2.2
Gi0/2, to R310.0.34.0/3013.3.3.3

Notice what an LSA is not: it isn't a route. R4 doesn't say "send LAN B traffic to me". It only describes what it is connected to. Turning descriptions into routes is the SPF step below.

Flooding: everyone gets every LSA

A router sends its LSA to its neighbours, and each neighbour passes an exact copy on to its own neighbours, until every router in the area has it. This is called flooding. Each LSA carries a sequence number, so a router that receives a copy it already has simply ignores it, and the LSA doesn't circle forever.

Gi0/0Gi0/1Gi0/0Gi0/2Gi0/0Gi0/1Gi0/1Gi0/1Gi0/2Gi0/0LAN A192.168.1.0/24R1RID 1.1.1.1R2RID 2.2.2.2R3RID 3.3.3.3R4RID 4.4.4.4LAN B192.168.4.0/24
  1. 1. R4 sends its LSA to both neighbours. It describes R4's three links: LAN B, the link to R2 and the link to R3.
  2. 2. R2 and R3 pass the same LSA on. They don't change it; R1 receives an exact copy of what R4 wrote.
  3. 3. R1 gets two copies and keeps one. The second copy has the same sequence number, so R1 acknowledges it and does not flood it again.

The LSDB: the same map on every router

Every router stores all the LSAs it receives in its link-state database (LSDB). Because flooding gives every router a copy of every LSA, all routers in an area end up with an identical LSDB: the same map of every router, link and subnet. When something changes, the router that saw it sends a new version of its LSA, and every map is updated.

SPF: from the map to the best paths

A map alone doesn't give directions. Each router runs the shortest path first (SPF) algorithm, also known as Dijkstra's algorithm, on its LSDB. SPF builds a tree with the router itself at the root and the cheapest path to every other router and subnet as branches. The best paths go into the routing table.

The map is identical everywhere, but each router stands at a different place on it, so each gets a different tree. R1's best way to LAN B starts with R2; R3's best way to LAN B is straight to R4. Same map, different starting point.

Cost: how paths are compared

Every OSPF interface has a cost, and the cost of a path is the sum of the costs of the interfaces a packet leaves through on the way. Lower total cost wins. By default Cisco works the cost out from the interface bandwidth:

cost = reference bandwidth ÷ interface bandwidth, with a default reference bandwidth of 100 Mbps and a minimum cost of 1.
10 Mbps → 100 ÷ 10 = 10 · 100 Mbps → 1 · 1 Gbps → 0.1, rounded up to 1.

In the square network, suppose the R1–R3 link is slower and its interfaces have cost 10, while every other interface has cost 1. R1 compares its two ways to LAN B:

Gi0/0Gi0/1Gi0/0cost 1Gi0/2Gi0/0cost 10Gi0/1Gi0/1cost 1Gi0/1Gi0/2cost 1Gi0/0LAN A192.168.1.0/24R1RID 1.1.1.1R2RID 2.2.2.2R3RID 3.3.3.3R4RID 4.4.4.4LAN B192.168.4.0/24
  1. 1. Over the top: R1 Gi0/1 (1) + R2 Gi0/1 (1) + R4 Gi0/0 to LAN B (1) = 3.
  2. 2. Along the bottom: R1 Gi0/2 (10) + R3 Gi0/1 (1) + R4 Gi0/0 (1) = 12.
  3. 3. SPF picks the lowest total: The path through R2 costs 3, so it goes into R1's routing table. The bottom path stays in the map as the alternative.
O = learned by OSPF. [110/3] = administrative distance 110 (OSPF's trust level) / metric 3 (the total cost). Next hop 10.0.12.2 is R2.
R1#show ip route ospf
      192.168.4.0/24 is subnetted, 1 subnets
O        192.168.4.0/24 [110/3] via 10.0.12.2, 00:02:11, GigabitEthernet0/1

The cost is counted on the way out of each router, which is why R4's LAN B interface is included and R1's LAN A interface is not.

Areas: keeping the map small

Flooding every LSA to every router works well for tens of routers. In a network with hundreds of routers and thousands of links, every router would store a huge LSDB, every small change would be flooded everywhere, and every router would rerun SPF each time. OSPF solves this with areas: groups of routers that share one LSDB.

  • LSAs describing individual links are flooded only inside their own area.
  • Each area has its own, smaller LSDB, so SPF is quicker and uses less memory.
  • A change in one area doesn't make routers in other areas rerun SPF.
  • Every area connects to the backbone, area 0.

The CCNA covers single-area OSPF: every router in area 0, as in the square network. Multi-area design is a CCNP topic, covered later in the beyond-CCNA part of this course.

Common mistakes

  • Thinking the process ID must match between routers. It is local to each router.
  • Thinking an LSA is a route. It describes links; SPF turns the map into routes.
  • Expecting a new router-id to take effect at once. It needs clear ip ospf process.
  • Assuming faster links always get lower costs. With the default reference bandwidth, 100 Mbps and faster all cost 1.
  • Thinking every router has the same routing table. They share the map, but each has its own best paths.

💡 Exam tip: know the router ID order (router-id command, highest up loopback, highest up interface), that OSPF's administrative distance is 110, the cost formula with its 100 Mbps default, and how to read [110/3] in a routing table entry.

Key takeaways

✅ Key takeaways
  • OSPF is an open-standard link-state IGP; every router runs its own process, with no central controller.
  • The process ID is local; the router ID is a unique 32-bit name chosen when the process starts.
  • Routers become neighbours by exchanging hellos on shared links.
  • Each router floods an LSA describing its links; every router stores them in an identical LSDB.
  • Each router runs SPF from its own position and installs the lowest-cost paths.
  • Cost = reference bandwidth ÷ interface bandwidth (default 100 Mbps, minimum 1), summed on the way out.
  • Areas keep the LSDB and flooding small; the CCNA uses a single area, area 0.

Check yourself

Predict · scenario 1

A router has no router-id command, a loopback 10.255.0.1 (up), and interfaces 192.168.1.1 and 10.0.12.1 (both up). What is its OSPF router ID?

Predict · scenario 2

What does a router do with an LSA it receives from a neighbour?

Predict · scenario 3

All routers in an area have identical LSDBs. Do they all have identical routing tables?

Predict · scenario 4

With the default reference bandwidth (100 Mbps), what is the OSPF cost of a 10 Mbps Ethernet interface?

Predict · scenario 5

R1's routing table shows O 192.168.4.0/24 [110/3] via 10.0.12.2. What is 3?

FAQ

Is OSPF controlled by one central router?
No. Every router runs its own OSPF process and makes its own decisions. They agree on the best paths because they all hold the same map (the LSDB) and run the same calculation on it, not because one router tells the others what to do.
Does the router ID have to be an IP address on the router?
No. It only looks like an IPv4 address. A router ID configured with the router-id command can be any 32-bit value, such as 1.1.1.1, as long as it is unique in the OSPF network.
Why do 100 Mbps, 1 Gbps and 10 Gbps links all show cost 1?
With the default reference bandwidth of 100 Mbps, any link of 100 Mbps or faster works out at 1 or less, and OSPF rounds up to a minimum of 1. Modern networks raise the reference bandwidth with auto-cost reference-bandwidth so faster links get lower costs; the configuration lessons show how.