What is OSPF ?

Introduction

Imagine you’re late for a meeting. You jump in your car, open your GPS, and ask it to find the fastest route. It scans the roads, traffic conditions, and construction zones, then gives you the best possible path to arrive on time.

A car chooses the shortest path to a destination using GPS, illustrating how OSPF works

That’s exactly how OSPF behaves in your network. Like a GPS, it constantly updates its view of the network and recalculates routes whenever something changes, always aiming for the shortest and most efficient path to your destination.

Diagram explaining what is OSPF, showing PC1 sending data to PC2 through routers R1 and R2 using the shortest path

Just like your GPS guides you to the best path, OSPF ensures that for example PC1 sends traffic to PC2 using the most optimal route available in our network.

OSPF in the Routing Landscape

Before we dive deeper into how OSPF works, it’s important to understand what kind of protocol it is and how it compares to others.

In a network, routers need a way to learn where different destinations are and how to reach them. They do this by using routing protocols, which fall into two main categories:

Visual comparison of routing protocols, showing IGP with RIP, EIGRP, OSPF, and IS-IS, and EGP with only BGP

EGP vs IGP

  • EGP (Exterior Gateway Protocol):
    Used to exchange routes between organizations, like between Internet Service Providers or large networks.
    Today, the only EGP still in common use is BGP (Border Gateway Protocol).

  • IGP (Interior Gateway Protocol):
    Used inside an organization’s network, between internal routers.
    This is where OSPF belongs.

Since OSPF is used within an organization, it’s classified as an IGP.

Types of IGPs

Within IGPs, protocols are categorized by how they exchange routing information:

IGP protocol types showing RIP, EIGRP, OSPF, and IS-IS

Distance-Vector protocols

Share information only with direct neighbors. Each router makes decisions based on what its neighbors report.
Example: RIP

Uses hop count as the main metric, fewer hops mean a better path, regardless of link quality.

Link-State protocols

Share detailed link information with all routers in the area. Each router has a synchronized map of the network.
Example: OSPF

Calculates the best path based on interface cost, often tied to bandwidth, for more accurate and efficient routing.

Hybrid protocols

Combine characteristics of both Distance-Vector and Link-State.
Example: EIGRP

EIGRP uses neighbor-based communication like Distance-Vector, but applies more advanced metrics and maintains a partial view of the topology making it faster and more accurate than RIP.

OSPF Sees the Whole Network

Let’s start with OSPF.
It’s a Link-State protocol, which means every router shares full details about its connected links. This allows each router to build a complete and synchronized map of the network.

Once the map is ready, each router runs the Dijkstra algorithm to calculate the shortest paths.

Router R1 declares it knows the entire network topology, showing how OSPF shares link information across all routers
R1 knows the full network topology. It doesn’t rely on its neighbors to guess the path.

RIP Has a Limited View

RIP works very differently.
It’s a Distance-Vector protocol, meaning each router only shares its known routes with direct neighbors. Routers then slowly build a view of the rest of the network, hop by hop.

Router R1 only knows its direct neighbors, illustrating how RIP has a limited view of the network
R1 only knows about its immediate neighbors.

Because of these constraints, RIP became too limited for modern networks.

What About EIGRP?

EIGRP is a bit different. It’s considered a hybrid routing protocol, combining features from both Distance-Vector and Link-State:

  • Like Distance-Vector, it exchanges routing information with neighbors.
  • But like Link-State, it uses advanced metrics and tracks the state of links more intelligently.

This makes EIGRP faster and more efficient than RIP.

However, there’s one big limitation:
EIGRP was originally Cisco proprietary, meaning it only worked in Cisco-only environments.

That’s why EIGRP is rarely used in multi-vendor networks where interoperability is critical.

For most enterprise networks, the need for standardized, vendor-neutral protocols made OSPF the preferred choice.

Summary Table

ProtocolTypeCharacteristicsVendor SupportTypical Use Case
RIPDistance VectorVery simple, 15-hop limitAll vendorsSmall or legacy networks
EIGRPHybridFast convergence, Cisco-only originallyCisco onlyCisco-specific environments
OSPFLink-StateFull topology view, open standardAll vendorsModern enterprise networks

How OSPF Works (Step by Step)

Just like a GPS constantly updates its map, OSPF routers follow a clear process to keep the network updated and choose the best paths.

This process includes five steps that every OSPF router performs to stay in sync with others and calculate the most efficient routes.

Step 1 – Establish Neighbor Adjacencies

OSPF starts by discovering other routers on the network.
Each router sends Hello packets to let others know it’s active.

OSPF routers exchange Hello packets to discover neighbors, forming relationships between R1, R2, R3, and R4

If another router receives the Hello packet, it replies to confirm it’s also running OSPF.
A neighbor relationship is then formed between them, allowing both routers to share routing information.

Step 2 – Exchange LSAs

After neighbors are discovered, routers begin exchanging Link-State Advertisements (LSAs).
Each router sends information about the links it has and the networks it is connected to.

OSPF routers R1 to R4 exchange Link-State Advertisements to share information about their links and networks

These LSAs are flooded across the entire area, so that every router receives the same information and can build a complete view of the network.

Step 3 – Build the LSDB

Each router collects all the received LSAs into a structure called the Link-State Database (LSDB).
This database represents the complete network topology from the router’s point of view.

Router R1 stores received LSAs in its Link-State Database to build a complete view of the network

Because all routers receive the same LSAs, their databases are identical.
This keeps the entire OSPF area consistent and synchronized.

Step 4 – Run the SPF Algorithm

Once a router has received all LSAs and built its own Link-State Database (LSDB), it runs the Shortest Path First (SPF) algorithm also known as Dijkstra’s algorithm to calculate the best routes to all destinations in the OSPF area.

Router R1 uses the LSDB built from LSAs to run the SPF algorithm and calculate the shortest paths

The router builds a tree of shortest paths, using itself as the starting point.
This helps it determine the most efficient way to reach every network in the area.

Step 5 – Install the Best Routes

After calculating the shortest paths, the router installs the best routes into its routing table.

Router R1 installs the best routes into its routing table after calculating shortest paths to each destination network

Thanks to OSPF, the router now knows how to reach each destination network efficiently.
It can then use these routes to forward traffic through the network, depending on what it learns from OSPF.

Summary

LLet’s recap what you’ve just learned:

  • Now you know what OSPF is: a dynamic routing protocol that builds a complete and synchronized map of the network.

  • It forms neighbor relationships, exchanges LSAs, builds a database, calculates optimal routes, and installs them.

  • It can adapts quickly to changes, using smart communication between routers.

Just like a GPS that constantly reroutes you in traffic, OSPF keeps your network optimized and efficient in real time.

Ready to Practice?

In the next lesson, we’ll move from theory to practice.
You’ll configure OSPF on real routers and see everything you’ve just learned come to life step by step.

Let’s get started.