OSPF doesn’t actually route traffic; it just tells other routers what paths are available, and then a separate routing table lookup decides which packet to send.
Let’s see how this plays out in a small, two-router network.
RouterA
interface GigabitEthernet0/0
ip address 192.168.1.1 255.255.255.0
ip ospf 1 area 0
RouterB
interface GigabitEthernet0/0
ip address 192.168.1.2 255.255.255.0
ip ospf 1 area 0
When these routers come online, they’ll both be shouting "Hey, I’m OSPF process 1, area 0, and I know about the 192.168.1.0/24 network!" They do this by sending "hello" packets every 10 seconds to a multicast address (224.0.0.5). If RouterA hears a hello from RouterB on Gi0/0, and RouterB hears one from RouterA, they’ll try to form an OSPF adjacency. This is the core of OSPF setup: establishing these neighbor relationships.
Once they’re adjacent, they exchange their Link State Advertisements (LSAs). These LSAs describe the local network segments each router is connected to. In our simple case, RouterA sends an LSA saying "I’m connected to 192.168.1.0/24," and RouterB does the same. All routers in the same OSPF area flood their LSAs to each other.
After hearing all the LSAs, each router builds a Link State Database (LSDB). This is a map of the entire OSPF area. From this map, each router independently runs the Dijkstra algorithm to calculate the shortest path to every other network. The results of this calculation populate the router’s main IP routing table. So, RouterA’s routing table will show a route for any networks RouterB knows about, and vice-versa, with the next hop being the directly connected interface.
The problem OSPF solves is dynamic routing. Without it, if you had a network with multiple paths, you’d have to manually configure static routes on every router. If a link goes down, you’d have to manually update all those static routes. OSPF automates this. When RouterA’s Gi0/0 interface goes down, it floods an LSA indicating its link to 192.168.1.0/24 is now down. All routers in the area see this, update their LSDBs, re-run Dijkstra, and update their routing tables. This convergence typically happens within seconds.
The key levers you control are the OSPF process ID, the network statements, and the area assignments. The process ID is locally significant; RouterA’s router ospf 1 doesn’t need to match RouterB’s router ospf 1. The network command is what tells OSPF which interfaces to run on and which networks to advertise. ip ospf 1 area 0 on an interface enables OSPF on that interface and assigns it to OSPF process 1, area 0. A wildcard mask is often used with the network command in router ospf configuration mode, e.g., network 192.168.1.0 0.0.0.255 area 0. This tells OSPF to look for interfaces within that subnet and advertise them.
The way OSPF elects a Designated Router (DR) and Backup Designated Router (BDR) on multi-access segments like Ethernet is crucial for efficiency. Instead of every router forming an adjacency with every other router (which would be N*(N-1)/2 adjacencies on a segment with N routers), only the DR and BDR form full adjacencies with all other routers. The other routers only form adjacencies with the DR and BDR. This dramatically reduces the number of LSAs exchanged and the processing load. The DR is elected based on the highest OSPF priority (default is 1) and then the highest router ID.
The most surprising thing about OSPF adjacency is how many states a router goes through before becoming "FULL." It starts as DOWN, then INIT (received a hello but not my own ID), then TWO-WAY (seen my own ID in a hello, indicating mutual acknowledgment), then EXCHANGE (exchanging database descriptor packets), LOADING (requesting and receiving LSAs), and finally FULL (LSDBs are identical). If you see an adjacency stuck in EXCHANGE or LOADING, it often means there’s a mismatch in MTU, hello/dead timers, or OSPF network types between neighbors.
The next concept you’ll grapple with is OSPF route summarization, where you aggregate routes at area boundaries to reduce the size of routing tables and the frequency of routing updates.