NetForge-AI
Networking CourseGuidedLessonsCommunityFeaturesProtocolsPricingPrivacyTerms
Sign inStart free
NetForge-AI
Networking CourseGuidedLessonsCommunityFeaturesProtocolsPricingPrivacyTerms
Sign inStart free
All lessons
Intermediate·20 minute read

OSPF explained: neighbors, areas and cost

Short answer

OSPF (Open Shortest Path First) is a link-state routing protocol. Routers on a shared link become neighbors by exchanging hello packets, flood descriptions of their links to each other, and each runs the shortest-path-first algorithm over the same map. The path with the lowest total cost wins, and OSPF routes carry administrative distance 110.

OSPF is a link-state routing protocol: every router shares what its links look like, builds the same map of the network, and runs a shortest-path calculation over it. This lesson covers how neighbors form, what area 0 is for, how cost picks a path, and the mismatches that stop an adjacency.

Open this lab

Link-state in one paragraph

A distance-vector protocol tells its neighbors "I can reach network X at distance N" and trusts their arithmetic. OSPF does something different: each router describes its own links — which networks it is attached to and what each link costs — and floods that description to every router in the area. Every router ends up holding the same link-state database, and each computes its own shortest-path tree from it.

Because every router works from the same map, OSPF converges quickly after a change and does not count to infinity the way a hop-count protocol can.

Turning OSPF on

You start an OSPF process, give the router a router ID, and list which interfaces take part with network statements. The network statement uses a wildcard mask (the inverse of the subnet mask) and names the area:

Edge-HQ(config)# router ospf 1
Edge-HQ(config-router)# router-id 1.1.1.1
Edge-HQ(config-router)# network 192.168.10.0 0.0.0.255 area 0
Edge-HQ(config-router)# network 10.10.10.0 0.0.0.3 area 0
Edge-HQ(config-router)# end
Edge-HQ# show ip route
O  192.168.20.0/24 [110/65] via 10.10.10.2, Se0/0/0
Note: The O at the start of the route means OSPF learned it. In [110/65], 110 is the administrative distance and 65 is the total cost to the destination.

What has to match for two routers to become neighbors

Two routers only form an adjacency when the hello packets they exchange agree. When an adjacency never comes up, check these in order:

Must matchWhat goes wrong if it doesn't
Area ID on the shared linkHellos are ignored; show ip ospf neighbor stays empty
Subnet and mask on the shared linkThe routers are not on the same network, so they never pair
Hello and dead timersHellos are rejected as incompatible
Authentication (if used)Hellos fail authentication and are dropped
Unique router IDsTwo routers with the same ID confuse the database

Areas and why area 0 is special

OSPF divides a large network into areas so that the detailed link-state flooding stays inside each area. Area 0 is the backbone: every other area must connect to it, and routes between areas pass through it. A small network is usually a single area, area 0.

A router with interfaces in two areas is an area border router; it summarises one area's networks into the other.

How cost chooses the path

Every OSPF interface has a cost, derived by default from a reference bandwidth divided by the interface's bandwidth — so faster links cost less. The cost of a route is the sum of the outgoing interface costs along the path, and the lowest total wins. Equal-cost paths can be used together.

You can override the calculation per interface with ip ospf cost, which is how you steer traffic onto a preferred link.

Verify it in the lab

show ip ospf neighbor lists the routers this one has formed adjacencies with. show ip route shows which OSPF routes were installed (the O lines). If the neighbor list is empty, return to the table above — the area, the subnet and the timers are the usual suspects.

Common questions

What is the administrative distance of OSPF?
110. A static route (1) or an EIGRP internal route (90) to the same network is preferred over an OSPF route; a RIP route (120) is not.
What does area 0 mean in OSPF?
Area 0 is the backbone area. Every other area must attach to it, and traffic between areas crosses it.
Why is my OSPF neighbor not forming?
The usual causes are a mismatched area ID, mismatched subnet or mask on the link, different hello/dead timers, or a network statement that does not cover the interface.
Why does the OSPF network command use a wildcard mask?
The wildcard marks which bits must match (0) and which are ignored (1). 0.0.0.255 matches every address in a /24; 0.0.0.3 matches a /30 link.
What is the OSPF router ID?
A 32-bit number written like an IP address that names the router inside OSPF. Set it with router-id; it must be unique in the OSPF domain.

Practise it

  • Guided build: two routers that learn each other's networks
  • Guided build: multi-area OSPF
  • Challenge: OSPF neighbors that never form

Practice this in the lab

Reading helps. Wiring it up yourself and breaking it makes it stick.

Open the lab
NetForge-AI

A browser-native network lab and networking course, beginner to advanced. Free account opens Module 1 + a 5-device lab; the Course & Lab Pass or All-Access Max opens the full course.

Product

  • Lab
  • 3D Live
  • Networking Course
  • Lessons
  • Guided Builds
  • Network Challenges
  • For Teachers
  • Community
  • Features

Course modules

  • 1 · Fundamentals
  • 2 · Addressing
  • 3 · Access (L2)
  • 4 · Connectivity
  • Final Weighted Exam

Resources

  • Command Reference
  • Free Networking Tools
  • Subnet Calculator
  • MAC Address Lookup
  • Port Number Lookup
  • OSI Model Chart
  • Simulator Comparisons
  • FAQ
  • About
  • Contact
  • Privacy Policy
  • Terms of Service

NetForge-AI is an independent educational platform and is not affiliated with, endorsed by, or sponsored by any networking vendor or certification body. All product names, protocols, and standards referenced are the property of their respective owners and are used for descriptive, educational purposes only.

© 2026 NetForge-AI. All rights reserved.Built for networking learners worldwide.