OSPF Routing Protocol: Everything You Need to Know for the CCNA Exam

Published on February 8, 2026 | By IT Cert Bound

1. What Is OSPF and Why It Replaced Older Protocols

Open Shortest Path First, universally known as OSPF, is one of the most widely deployed interior gateway protocols (IGPs) in enterprise networking today. Defined in RFC 2328 for OSPFv2 (IPv4) and RFC 5340 for OSPFv3 (IPv6), OSPF is an open-standard routing protocol, meaning it is not proprietary to any single vendor. This openness is one of the primary reasons it became the industry favorite over older protocols like RIP and even Cisco's proprietary EIGRP in multi-vendor environments.

To understand why OSPF rose to prominence, it helps to look at what came before it. The Routing Information Protocol (RIP) was one of the earliest dynamic routing protocols used in IP networks. RIP is a distance-vector protocol that uses hop count as its sole metric, with a maximum hop count of 15. Any destination more than 15 hops away is considered unreachable. RIP also broadcasts its entire routing table to neighbors every 30 seconds, regardless of whether anything has changed. These limitations made RIP impractical for anything beyond small networks. Convergence was slow, bandwidth was wasted on periodic updates, and the hop count limit severely restricted network size.

OSPF was designed from the ground up to address every one of these shortcomings. It uses a cost metric based on interface bandwidth rather than a simple hop count, it supports networks of virtually unlimited size through its hierarchical area design, and it converges dramatically faster because routers only send updates when a topology change actually occurs. Instead of broadcasting full routing tables on a timer, OSPF routers exchange link-state advertisements (LSAs) that describe the state of their directly connected links. Each router then independently builds a complete map of the network topology and calculates the shortest path to every destination using Dijkstra's Shortest Path First (SPF) algorithm.

Key Distinction: RIP is a distance-vector protocol that learns routes by rumor (it trusts what neighbors tell it). OSPF is a link-state protocol that builds a complete topological map of the network, so every router has the same comprehensive view and can independently calculate the best paths.

2. OSPF Fundamentals: Link-State Protocol and Dijkstra's Algorithm

OSPF belongs to the family of link-state routing protocols. The term "link-state" refers to the fact that each router advertises the state (up or down, cost, network type) of its own directly connected links to all other routers in the same OSPF area. This is fundamentally different from distance-vector protocols, where routers only share their routing tables with directly connected neighbors.

The process works as follows. When an OSPF router comes online, it discovers its neighbors through the exchange of Hello packets. Once neighbor relationships are established, each router generates link-state advertisements (LSAs) that describe its connected interfaces, their IP addresses, subnet masks, costs, and the neighbors reachable through each link. These LSAs are flooded throughout the area so that every router receives the same set of LSAs. Each router stores all the LSAs it receives in a local database called the Link-State Database (LSDB). Because every router in an area receives the same LSAs, every router in that area has an identical LSDB.

With a complete LSDB in hand, each router runs Dijkstra's Shortest Path First algorithm to build a shortest-path tree (SPT) with itself as the root. The algorithm evaluates every possible path to every destination network and selects the path with the lowest cumulative cost. The results are then installed into the router's routing table. Because every router performs this calculation independently using the same data, the network achieves a consistent, loop-free forwarding topology.

OSPF Packet Types

OSPF uses five distinct packet types to manage neighbor discovery, database synchronization, and route updates. Understanding these is essential for the CCNA exam:

Type Packet Name Purpose
1 Hello Discover and maintain neighbor relationships
2 Database Description (DBD) Summarize LSDB contents during initial adjacency
3 Link-State Request (LSR) Request specific LSAs from a neighbor
4 Link-State Update (LSU) Send requested LSAs or flood topology changes
5 Link-State Acknowledgment (LSAck) Confirm receipt of LSAs (ensures reliability)
OSPF uses IP protocol number 89 directly, not TCP or UDP. Hello packets are sent to the multicast address 224.0.0.5 (AllSPFRouters) on broadcast and point-to-point network types. On multi-access networks, updates to the DR/BDR use 224.0.0.6 (AllDRouters).

3. OSPF Areas and the Role of Area 0

One of OSPF's most powerful design features is its support for a hierarchical, multi-area architecture. An OSPF area is a logical grouping of routers and networks that share the same link-state database. By dividing a large network into multiple areas, administrators can significantly reduce the amount of routing information each router must process, lower CPU and memory consumption, and contain the blast radius of topology changes so that an instability in one area does not trigger SPF recalculations across the entire network.

Why Area 0 Is Special

Area 0, also called the backbone area, is the core of every OSPF domain. All other areas must connect directly to Area 0, either through a physical link or through a virtual link. This is not merely a best practice; it is a hard requirement of the OSPF specification. The backbone area serves as the transit area for all inter-area traffic. When a packet needs to travel from a network in Area 1 to a network in Area 2, it must pass through Area 0 along the way. This star topology ensures a loop-free inter-area routing architecture.

Routers that sit at the boundary between Area 0 and another area are called Area Border Routers (ABRs). An ABR has interfaces in at least two areas, one of which must be Area 0. ABRs are responsible for summarizing routing information between areas by generating Type 3 Summary LSAs. Routers that connect the OSPF domain to an external routing domain (such as the internet or a network running a different protocol) are called Autonomous System Boundary Routers (ASBRs).

Key Area Concepts for the CCNA

  • All OSPF areas must connect to Area 0 (the backbone)
  • Routers within the same area share an identical LSDB
  • ABRs connect non-backbone areas to Area 0 and summarize routes
  • The CCNA 200-301 exam focuses primarily on single-area OSPF, but you must understand the concept of areas and why Area 0 exists
  • Virtual links can be used to connect a disconnected area to Area 0, but this is considered a temporary fix, not a design goal

4. OSPF Neighbor Relationships and States

Before two OSPF routers can exchange routing information, they must first form a neighbor relationship. This process is initiated by Hello packets and progresses through a series of well-defined states. Understanding each state is critical for the CCNA exam and for real-world troubleshooting, because a neighbor stuck in a particular state tells you exactly where the adjacency formation process is failing.

The Seven OSPF Neighbor States

Down: This is the initial state. The router has not received any Hello packets from this neighbor. When a router first sends a Hello, the neighbor entry is created in Down state. If a neighbor has been active but its Dead timer expires without receiving a new Hello, the neighbor transitions back to Down.

Init: A Hello packet has been received from the neighbor, but it does not yet list the local router's Router ID in its "neighbor" field. This means the neighbor knows about us, but we have not confirmed that the neighbor has heard us. One-way communication is established.

2-Way: This is a pivotal state. The router has received a Hello from the neighbor that includes the local router's Router ID in its neighbor list, confirming bidirectional communication. At this point on multi-access networks, the DR/BDR election takes place. On point-to-point links, the routers proceed directly to forming a full adjacency. On multi-access networks, routers that are neither the DR nor the BDR (called DROther routers) will remain in the 2-Way state with each other; they only form full adjacencies with the DR and BDR.

ExStart: The two routers negotiate which one will be the master and which will be the slave for the database exchange process. The router with the higher Router ID becomes the master, which means it controls the sequence numbering of DBD packets.

Exchange: The routers exchange Database Description (DBD) packets that contain summaries of the LSAs in their respective LSDBs. Each router examines the summaries to determine which LSAs it is missing or which are more recent than what it currently has.

Loading: Based on the DBD exchange, each router sends Link-State Request (LSR) packets to ask for any LSAs it needs. The neighbor responds with Link-State Update (LSU) packets containing the full LSA data. This process continues until both routers have synchronized their databases.

Full: The databases are fully synchronized. The adjacency is complete, and the routers are now peers that share a common view of the network topology. This is the operational state for a healthy OSPF adjacency. In show command output, you should see "FULL" for adjacencies with the DR and BDR on multi-access networks, and "FULL" for all adjacencies on point-to-point links.

If a neighbor is stuck in the ExStart or Exchange state, the most common cause is an MTU mismatch between the two interfaces. OSPF includes the interface MTU in DBD packets, and if the values do not match, the adjacency will not progress. Always verify that MTU settings are consistent on both sides of an OSPF link.

5. Router ID Selection Process

Every OSPF router must have a unique 32-bit Router ID (RID) that identifies it within the OSPF domain. The Router ID is written in dotted decimal notation, just like an IP address, but it is not necessarily an IP address that is reachable on the network. The selection process follows a strict priority order:

  1. Manually configured Router ID: If you explicitly set the Router ID using the router-id command under the OSPF process, that value is used regardless of any interface addresses. This is the recommended best practice because it gives you full control and prevents unexpected changes if interfaces go down.
  2. Highest loopback interface IP: If no Router ID is manually configured, OSPF selects the highest IP address among all active loopback interfaces. Loopback interfaces are preferred because they never go down (they are virtual interfaces), providing a stable Router ID.
  3. Highest active physical interface IP: If there are no loopback interfaces configured, OSPF selects the highest IP address among all active physical interfaces at the time the OSPF process starts.
The Router ID is selected when the OSPF process first starts. If you change the Router ID (by configuring a loopback or using the router-id command), the change does not take effect until the OSPF process is restarted with clear ip ospf process or the router is reloaded. The exam loves to test this nuance.
! Best practice: Manually set the OSPF Router ID Router(config)# router ospf 1 Router(config-router)# router-id 1.1.1.1 ! Alternative: Use a loopback for automatic RID selection Router(config)# interface loopback 0 Router(config-if)# ip address 1.1.1.1 255.255.255.255

6. DR/BDR Election on Multi-Access Networks

On multi-access network segments (such as Ethernet LANs), OSPF elects a Designated Router (DR) and a Backup Designated Router (BDR) to reduce the amount of OSPF traffic on the segment. Without a DR, every router on the segment would need to form a full adjacency with every other router, creating an O(n-squared) problem. The DR acts as a central point of contact: all routers on the segment form full adjacencies only with the DR and BDR, and the DR is responsible for flooding LSAs to all other routers on the segment.

How the Election Works

The DR/BDR election is based on two criteria, evaluated in this order:

  1. OSPF Interface Priority: The router with the highest OSPF priority on that interface becomes the DR, and the second highest becomes the BDR. The default priority is 1. Setting a router's priority to 0 makes it ineligible for DR or BDR election on that segment.
  2. Router ID (tiebreaker): If priorities are equal, the router with the highest Router ID wins the election.
The DR/BDR election is non-preemptive. Once a DR is elected, it remains the DR even if a router with a higher priority or Router ID joins the segment later. The new router will only become DR if the current DR fails. This is a frequently tested concept on the CCNA exam.

Routers that are neither the DR nor the BDR are classified as DROther. DROther routers remain in the 2-Way state with each other and only achieve Full adjacency with the DR and BDR. This is normal behavior, not an error.

! Set OSPF priority to influence DR election Router(config)# interface GigabitEthernet0/0 Router(config-if)# ip ospf priority 255 ! Prevent a router from becoming DR on this interface Router(config)# interface GigabitEthernet0/1 Router(config-if)# ip ospf priority 0
DR/BDR elections only occur on broadcast and non-broadcast multi-access (NBMA) network types. Point-to-point links do not elect a DR/BDR because there are only two routers on the segment and the overhead reduction would be meaningless.

7. OSPF Cost Metric and Bandwidth Relationship

OSPF uses cost as its metric for path selection. The cost of a route is the sum of the costs of all outgoing interfaces along the path from the local router to the destination network. The cost of an individual interface is calculated using a simple formula:

OSPF Cost Formula: Cost = Reference Bandwidth / Interface Bandwidth

By default, the reference bandwidth is 100 Mbps (100,000,000 bps). This means a 100 Mbps Fast Ethernet interface has a cost of 1, a 10 Mbps Ethernet interface has a cost of 10, and a 1.544 Mbps T1 serial link has a cost of 64. However, this default reference bandwidth creates a significant problem in modern networks: any interface with a bandwidth of 100 Mbps or higher (Fast Ethernet, Gigabit Ethernet, 10 Gigabit Ethernet) all receive a cost of 1, making them indistinguishable to OSPF.

The solution is to increase the reference bandwidth to a value that accommodates your fastest links. For example, setting the reference bandwidth to 10,000 (representing 10 Gbps) would give a 10 Gbps link a cost of 1, a 1 Gbps link a cost of 10, and a 100 Mbps link a cost of 100, providing meaningful differentiation.

Interface Bandwidth Cost (Default 100 Mbps ref) Cost (10 Gbps ref)
Serial (T1) 1.544 Mbps 64 6477
Ethernet 10 Mbps 10 1000
Fast Ethernet 100 Mbps 1 100
Gigabit Ethernet 1 Gbps 1 10
10-Gigabit Ethernet 10 Gbps 1 1
! Change the reference bandwidth (must be consistent on ALL routers) Router(config)# router ospf 1 Router(config-router)# auto-cost reference-bandwidth 10000 ! Alternatively, manually set cost on a specific interface Router(config)# interface GigabitEthernet0/0 Router(config-if)# ip ospf cost 5
When you change the reference bandwidth, you must change it on every router in the OSPF domain to ensure consistent cost calculations. Cisco IOS will display a warning message reminding you of this whenever you use the auto-cost reference-bandwidth command.

8. Single-Area OSPF Configuration with Cisco IOS

The CCNA 200-301 exam heavily emphasizes single-area OSPF configuration. In a single-area deployment, all routers and networks belong to Area 0. While this does not leverage the hierarchical benefits of multi-area OSPF, it is simpler to configure and is perfectly adequate for small to medium-sized networks.

The Network Command

The network command under the OSPF router configuration mode does not announce networks directly. Instead, it tells the OSPF process which locally connected interfaces should participate in OSPF. Any interface whose IP address falls within the range specified by the network command and wildcard mask will be activated for OSPF, meaning OSPF Hello packets will be sent out of that interface and the connected network will be advertised.

Complete Configuration Example

Consider a router with the following interfaces: GigabitEthernet0/0 (192.168.1.1/24 connected to the LAN), GigabitEthernet0/1 (10.0.0.1/30 connected to another router), and a Loopback0 (1.1.1.1/32 used as the Router ID). Here is the full OSPF configuration:

! Enter global configuration mode Router# configure terminal ! Create a loopback interface for a stable Router ID Router(config)# interface loopback 0 Router(config-if)# ip address 1.1.1.1 255.255.255.255 Router(config-if)# exit ! Start the OSPF process (process ID 1 is locally significant) Router(config)# router ospf 1 ! Explicitly set the Router ID (best practice) Router(config-router)# router-id 1.1.1.1 ! Enable OSPF on the LAN interface in Area 0 Router(config-router)# network 192.168.1.0 0.0.0.255 area 0 ! Enable OSPF on the WAN link in Area 0 Router(config-router)# network 10.0.0.0 0.0.0.3 area 0 ! Advertise the loopback network Router(config-router)# network 1.1.1.1 0.0.0.0 area 0 ! Prevent OSPF Hellos on the LAN (no need to find neighbors there) Router(config-router)# passive-interface GigabitEthernet0/0 ! Set the reference bandwidth for modern networks Router(config-router)# auto-cost reference-bandwidth 10000 Router(config-router)# exit

Understanding the Wildcard Mask

The wildcard mask in the OSPF network command is the inverse of the subnet mask. Where a subnet mask has a 1, the wildcard mask has a 0, and vice versa. For example, a subnet mask of 255.255.255.0 corresponds to a wildcard mask of 0.0.0.255. A /30 subnet mask of 255.255.255.252 becomes a wildcard mask of 0.0.0.3. The wildcard mask defines which bits of the IP address must match exactly (0 bits) and which bits can vary (1 bits).

The Passive Interface Command

The passive-interface command tells OSPF to stop sending Hello packets out of a specified interface. The network connected to that interface is still advertised into OSPF; the router simply will not attempt to discover or form neighbor relationships through that interface. This is used on interfaces connected to end-user LANs, where there are no other OSPF routers and sending Hellos would be wasteful and a potential security risk.

! Alternative: Make all interfaces passive, then selectively activate Router(config-router)# passive-interface default Router(config-router)# no passive-interface GigabitEthernet0/1
Process ID vs. Area ID: The OSPF process ID (the number after router ospf) is locally significant to the router. It does not need to match between neighbors. However, the Area ID specified in the network command must match between neighbors for an adjacency to form.

9. Useful Show and Debug Commands

Knowing the right verification and troubleshooting commands is just as important as knowing how to configure OSPF. The CCNA exam expects you to interpret the output of these commands to identify issues and confirm correct operation.

show ip ospf neighbor

This is your go-to command for verifying OSPF adjacencies. It displays the Neighbor ID (Router ID of the neighbor), the current state of the adjacency, the Dead timer countdown, the neighbor's address, and the local interface connected to that neighbor.

Router# show ip ospf neighbor Neighbor ID Pri State Dead Time Address Interface 2.2.2.2 1 FULL/DR 00:00:33 10.0.0.2 Gi0/1 3.3.3.3 1 FULL/BDR 00:00:37 10.0.0.3 Gi0/1 4.4.4.4 1 2WAY/DROTHER 00:00:31 10.0.0.4 Gi0/1

In this output, notice that the local router has a Full adjacency with the DR (2.2.2.2) and BDR (3.3.3.3), but only a 2-Way relationship with the DROther (4.4.4.4). This is completely normal on a multi-access segment.

show ip route ospf

This command filters the routing table to display only routes learned through OSPF. OSPF routes are marked with "O" for intra-area routes, "O IA" for inter-area routes, and "O E1" or "O E2" for external routes.

Router# show ip route ospf O 192.168.2.0/24 [110/20] via 10.0.0.2, 00:15:33, GigabitEthernet0/1 O 192.168.3.0/24 [110/30] via 10.0.0.2, 00:15:33, GigabitEthernet0/1 O 172.16.0.0/24 [110/20] via 10.0.0.3, 00:12:10, GigabitEthernet0/1

The numbers in brackets represent [administrative distance/metric]. OSPF has a default administrative distance of 110. The metric is the total cost to reach the destination.

show ip ospf interface

This command provides detailed OSPF information for each interface, including the area assignment, cost, network type, hello and dead intervals, DR/BDR addresses, and neighbor count. It is invaluable for verifying configuration and diagnosing mismatches.

Router# show ip ospf interface GigabitEthernet0/1 GigabitEthernet0/1 is up, line protocol is up Internet Address 10.0.0.1/30, Area 0 Process ID 1, Router ID 1.1.1.1, Network Type BROADCAST, Cost: 1 Transmit Delay is 1 sec, State DROTHER, Priority 1 Designated Router (ID) 2.2.2.2, Interface address 10.0.0.2 Backup Designated Router (ID) 3.3.3.3, Interface address 10.0.0.3 Timer intervals configured, Hello 10, Dead 40, Wait 40, Retransmit 5 Neighbor Count is 3, Adjacent neighbor count is 2

Additional Useful Commands

! View the LSDB Router# show ip ospf database ! View OSPF process summary including Router ID Router# show ip ospf ! Brief interface overview Router# show ip ospf interface brief ! Debug OSPF adjacency events (use with caution in production) Router# debug ip ospf adj ! Debug Hello packet exchange Router# debug ip ospf hello
On the CCNA exam, you may be presented with show command output and asked to identify an issue. Pay close attention to neighbor states (stuck in Init, ExStart, or 2-Way where Full is expected), mismatched Hello/Dead timers, mismatched area IDs, and incorrect network type assignments. These are the most common OSPF problems the exam tests.

10. CCNA Exam Tips for OSPF Questions

OSPF is one of the most heavily tested topics on the CCNA 200-301 exam, appearing in the IP Connectivity domain which accounts for 25% of the total exam score. Here is a focused summary of the concepts and pitfalls you need to master before exam day:

Must-Know Facts for Exam Day

  • OSPF uses protocol number 89 and multicast addresses 224.0.0.5 (AllSPFRouters) and 224.0.0.6 (AllDRouters)
  • Default Hello interval is 10 seconds on broadcast and point-to-point networks, 30 seconds on NBMA networks
  • Default Dead interval is 4 times the Hello interval (40 seconds on broadcast/point-to-point)
  • Hello and Dead timers must match between neighbors or the adjacency will not form
  • Area IDs must match between neighbors on the same link
  • Subnet mask must match between neighbors (except on point-to-point links)
  • Authentication type and credentials must match if authentication is configured
  • Administrative distance of OSPF is 110
  • The OSPF process ID is locally significant and does not need to match between routers
  • DR/BDR election is non-preemptive

Common Exam Scenarios

Scenario 1 - Neighbors not forming: You are shown a topology where two routers are connected but OSPF neighbors are not forming. Check the following in order: Are the interfaces in the same subnet? Are they in the same OSPF area? Do the Hello/Dead timers match? Is one interface set as passive? Is there an ACL blocking protocol 89? Is the authentication configuration consistent?

Scenario 2 - Suboptimal routing: Traffic is taking a longer path than expected. Check the OSPF cost on each interface along both paths. Remember that all interfaces 100 Mbps and above have the same default cost of 1. Verify whether the reference bandwidth has been adjusted, and whether it has been set consistently on all routers.

Scenario 3 - DR election questions: You are given OSPF priorities and Router IDs and asked to identify the DR and BDR. Remember: highest priority wins, Router ID breaks ties, a priority of 0 means the router cannot be DR or BDR, and the election is non-preemptive.

Configuration Checklist

When configuring single-area OSPF on the exam, always follow this sequence:

  1. Assign IP addresses to all interfaces and bring them up
  2. Create a loopback interface or manually assign a Router ID
  3. Start the OSPF process with router ospf [process-id]
  4. Use network commands with correct wildcard masks and area 0
  5. Set passive interfaces on LAN segments where no OSPF neighbors exist
  6. Adjust the reference bandwidth if the network has links faster than 100 Mbps
  7. Verify with show ip ospf neighbor and show ip route ospf
When in doubt about wildcard mask syntax, remember that using network [ip] 0.0.0.0 area 0 matches only that exact IP address. This is the most precise way to enable OSPF on a specific interface and is commonly used in practice and on the exam. For example, network 192.168.1.1 0.0.0.0 area 0 enables OSPF only on the interface that has the IP address 192.168.1.1.

Wrapping Up

OSPF is the backbone of modern enterprise routing and one of the most important topics on the CCNA 200-301 exam. By understanding its link-state operation, how neighbors form adjacencies through the seven states, the role of areas and the backbone, the DR/BDR election process, and how cost drives path selection, you will have a solid foundation not only for passing the exam but for working with real production networks.

Focus your study on single-area OSPF configuration using the network command, wildcard masks, and passive interfaces. Practice reading and interpreting show command output, especially show ip ospf neighbor, show ip route ospf, and show ip ospf interface. Know the neighbor requirements that must match (area, timers, authentication, subnet) and the ones that do not need to match (process ID, Router ID). Build labs in Cisco Packet Tracer or GNS3 and configure OSPF between multiple routers to see these concepts in action.

For more in-depth study on IP Connectivity topics, visit our IP Connectivity Study Guide, or test your knowledge with our Practice Questions and Interactive Labs.