OSPF Configuration and Concepts Explained
Routers connect different IP subnets in a network. To connect them, they learn all network paths, select the best route for every subnet from all available paths, and save the chosen path in the routing table. A routing protocol automates this process. OSPF (Open Shortest Path First) is a routing protocol.
OSPF Terminology and Concepts
OSPF uses various terms to describe its functions and features. This section describes the essential terms you need for understanding, implementing, and managing OSPF in a network.
Link-state
OSPF is a link-state protocol. A link is a router's interface connected to an IP subnet. When you add an interface to the OSPF process, OSPF considers the interface as a link. A link has two states: up and down. The up state shows the link (interface) is operational, and OSPF can reach the IP subnet connected to the link. The down state indicates that the link is not functional, and OSPF cannot reach the IP subnet connected to it.
Hierarchical Design and Areas
OSPF uses areas in a hierarchical design to limit and control the routing information shared between OSPF routers. It implements a two-layer hierarchy: backbone area and non-backbone areas.
The backbone area sits in the center of the network. Routers running in this area keep detailed routing information about all routes of the network. They share routing information between all non-backbone areas. A non-backbone area limits the routing information shared between routers. All routers within a non-backbone area share and store detailed routing information only about routes available inside the area. For routes outside the area, they use the summarized version of routing information.

The following table lists essential terms used in the hierarchical design and the area concept.
| Term | Description |
| Backbone area | A special area to which all other areas must connect. |
| Area | A set of contiguous routers that share the same routing information. |
| Backbone routers | Routers in the backbone area |
| Internal routers | Routers in areas off the backbone |
| ABR | A router that connects the area to the backbone area |
| Intra-area route | A route within the same area |
| Inter-area route | A route between the areas |
DR, BDR, DROTHER
OSPF uses the concepts of DR, BDR, and DROTHER in a broadcast network to minimize routing information exchanged between routers. In a broadcast network, it designates one router as DR. The designated router shares routing updates with all other routers. BDR is a hot standby router for DR. BDR maintains a backup copy of all databases running on DR. If DR fails, BDR immediately becomes DR. Apart from DR and BDR, all remaining routers are called DROTHERs.
DROTHERs exchange routing information only through the DR. If a DROTHER has a routing update, it shares that with DR, and then DR shares it with all others. DROTHERs use the multicast address 224.0.0.6 to talk to the DR. DR and BDR use the multicast address 224.0.0.5 to speak and share routing information with other routers.
OSPF routers use OSPF priority and RID to elect a DR and BDR. The router with the highest OSPF priority on a segment becomes the DR for that segment. The router with the second-highest priority becomes the BDR for that segment. If you do not change the default priority, routers use RID to elect a DR and a BDR. The router with the highest RID becomes the DR. The router with the second-highest RID becomes the BDR. All other routers become DROTHERs. It selects a DR and a BDR for every Ethernet broadcast segment. For example, if a network has twenty VLANs, it will have twenty DRs and twenty BDRs.

OSPF uses the concepts of DR, BDR, and DROTHER only in broadcast networks. In a non-broadcast network, it does not use this concept.
Hello protocol
OSPF utilizes the Hello protocol to discover OSPF routers within the network and maintain relationships with its neighbors. Hello packets are sent to the multicast address 224.0.0.5.
OSPF database
OSPF maintains two types of databases: the neighborship database and the topological database. It uses the neighborship database to store a list of all OSPF routers. It uses the topological database to store information about all LSA packets.
Link State Advertisement (LSA)
LSA is an OSPF data packet containing link-state and routing information. OSPF routers share LSA packets only with adjacent routers.
LSDB
An LSDB is a collection of all LSAs received by the OSPF router. Each LSA has a unique sequence number. OSPF stores an LSA in LADB with its sequence number. Adjacent routers maintain the same LSDB.
RID
Each router in an OSPF network requires a unique ID. This ID is known as the OSPF Router ID or OSPF RID. The OSPF RID must be unique across the entire OSPF network. Routers use OSPF RID to identify other OSPF routers in the network. All messages generated and processed by OSPF routers include OSPF RID. A router uses the following process to choose its OSPF RID.
- It checks the running configuration to find the manually configured OSPF RID. You can configure a custom OSPF RID using the router-id rid command. If the router finds a custom OSPF RID, it uses that and does not check the next option.
- If it does not find a custom OSPF RID, it uses loopback interfaces as the second option. If a loopback interface has an IP configuration and the interface status is up, the router uses its IP address as the OSPF RID. If multiple loopback interfaces are up and have an IP configuration, it selects the loopback interface with the highest numeric IP address and uses it as the OSPF RID.
- If no loopback interface exists or all loopback interfaces with an IP configuration are down, the router uses the third option. It picks the highest IP address on its active interfaces and uses it as the OSPF RID.
- If no interface is active, the OSPF process does not start.

Neighbors
OSPF neighbors are two or more routers that have an interface in the same network and have the common configuration values. These configuration values are Area ID, Network ID, Authentication, Hello and Dead Intervals, Stub Flag, and MTU Size match. These are also known as neighborship requirements.
Adjacency
An OSPF router shares routing updates only with its adjacent neighbors. An adjacency is a relationship between two adjacent routers that permits them to exchange routing updates directly. Only neighbors become adjacent. The entire process goes through the following seven states.
- Down state
- Init state
- Two-way state
- Exstart state
- Exchange state
- Loading state
- Full state
The first three states establish neighbor relationships, and the last four build adjacent relationships.
Down state
An OSPF process always starts in the down state. In this state, it selects the OSPF RID. After choosing the RID, the router sends Hello packets from all active interfaces and waits for a response from other OSPF routers.

Init state
A router enters this state when it receives a Hello packet from a router not listed in its neighbor list. The router matches the received Hello packet's parameters with the locally configured parameters. If the required parameters for the neighborship match, it adds the sender router to the neighbor list. After adding the sender router to the neighbor list, it replies with its Hello Packet. The Hello Packet contains the sender's RID in the neighbor list field.

Two-way state
A router enters this state when it receives a reply from a router not available in its neighbor list. This message informs the router that another router, which has added this router to its neighbor list, exists on the network. If this router is willing to build a neighborship, it can reply with another Hello packet. If the router replies, both routers enter the two-way state. If two routers reach this state, it means that both routers have met all OSPF configuration requirements to become neighbors. At this point, they are neighbors and ready to exchange their routing information.

Exstart state
How routers will share routing information depends on the network type. In a broadcast multi-access network, they share routing information through the DR and BDR. In a point-to-point network, they directly share routing information. In a broadcast multi-access network, an election process occurs at this point to select the designated router (DR) and the backup designated router (BDR) for the segment. Routers select a DR and a BDR for every segment. Apart from the DR and BDR, all other routers in the segment are known as DROTHERs. The only exception to a segment not having a DR and BDR is on a WAN point-to-point link.

In each segment, routers form adjacencies only with the DR and BDR. An OSPF router talks to a DR using the IP multicast address 224.0.0.6. The DR and the BDR talk to all OSPF routers using the 224.0.0.5 multicast IP address. In each adjacency, every router compares its RID with the RID of the DR. If it has a higher RID, it becomes the master. If it has a lower RID, it becomes the slave. The master starts the exchange process. The remaining router in the adjacency will be the slave.

Note that the DR is not necessarily the master of the exchange process. The router with the higher RID will be the master of the exchange process.
Exchange state
After finalizing their roles in the exchange process, they share a list of LSAs in their databases. An LSA is a small portion of a database. It contains information only about a specific link. Each LSA has a unique ID. Routers use it to check which LSAs they already have and then request only the LSAs they do not have from the other router.

Let us take an example. The master sends a list of LSAs from its database to the slave. The list contains information about ten LSAs. The slave checks its database and finds four of those LSAs. Therefore, it will only request six LSAs using a Link-State Request packet. Similarly, the master compares the list it receives from the slave and requests the LSAs it does not have in its database.
Loading state
In the loading state, the master and slave provide the requested LSAs and incorporate the received LSAs into their respective databases. Then, they send an acknowledgment LSA to update each other.

Full state
Master and slave will repeat the exchange and loading states until they have an identical database. Once the master and the slave are synchronized, you can consider them to be in a full state.

Shortest Path First (SPF) Algorithm
OSPF routing protocol uses the SPF (Shortest Path First) algorithm to calculate and select the fastest path. The SPF algorithm uses the bandwidth as the metric. The bandwidth tells how fast a link is. If a link has high bandwidth, it will be fast. If it has less bandwidth, it will be slow. For example, a 100 Mbps Ethernet link will transfer data faster than a 56 Kbps serial link. A higher bandwidth link also has less overhead than a lower bandwidth link. Overhead directly affects the data flow on the link. Lower overhead results in faster data transfer speeds. SPF uses these things to calculate the cost of links. Cost is inversely proportional to bandwidth. Higher bandwidth costs less. Lower bandwidth costs more. It uses the following formula to calculate the link cost.
Cost = Reference bandwidth / Interface bandwidth in bps
RFC 2338 defines the reference bandwidth as an arbitrary value. Vendors use their own reference bandwidth. Cisco uses 100Mbps (108) bandwidth as the reference bandwidth. Cisco routers use the following formula to calculate the cost.
Cost = 108/interface bandwidth in bps
- Cost is a positive integer value.
- If the calculated cost is in decimal, it converts that into the nearest positive integer.
- If the calculated cost is smaller than one, it uses one as the cost.
| Link/Interface Type | Bandwidth | Actual cost | Final cost |
| Ethernet Link | 10Mbps | 100000000/10000000 = 10 | 10 |
| FastEthernet Link | 100Mbps | 100000000/100000000 = 1 | 1 |
| Serial Link | 1544Kbps(default) | 100000000/1544000 = 64.76 | 64 |
OSPF Configuration (Packet Tracer Example)
OSPF configuration practice involves the following steps.
- Creating a practice lab and assigning an IP configuration to all interfaces
- Testing connectivity between all interfaces
- Enabling OSPF routing on all routers
- Verifying and testing OSPF configuration
Creating a practice LAB
Add three routers, one PC, and one Server to the workspace. Connect devices and assign an IP configuration as shown in the following image.

Alternatively, you can download this lab from the following link.
Download the pre-configured lab with IP configuration.Testing connectivity
You can use the ping command to test connectivity. A ping command reply verifies devices have connectivity.
Testing connectivity from R1

Testing connectivity from R2

Testing connectivity from R3

OSPF Routing commands
The following two steps in global configuration mode enable OSPF routing on the router.
- Enable an OSPF process.
- Assign an area to the interfaces.
The following command enables an OSPF process on the router.
Router(config)# router ospf [process_ID]
Process_ID
You can run multiple OSPF processes on a single router. The router uses the process_ID to differentiate between OSPF processes. The process_ID is a numeric value. It can be any number from 1 to 65,535. It is locally significant. You do not need to match it on all routers. You can use a different process ID on each router. The following command assigns an area to the interface.
Router(config-router)# network [IP_network_#] [wildcard_mask] area [area number]
Each router interface requires a valid IP address to function correctly. This command matches the given IP address with the IP address of all interfaces. If an interface's IP address matches the given IP address, it enables the OSPF process on that interface and adds that interface to the specified OSPF area.
You can use a wildcard mask to match multiple interfaces with a single configuration line. A wildcard mask tells the router the part of the address it should match. It contains wildcard bits. In binary, 0 is a matching bit, and 1 is an ignoring bit. In decimal, number 0 represents a matching bit while number 255 represents an ignoring bit. For example, the mask 0.255.255.255 indicates a match in the first byte of the network number.
The area ID is the area number for which you want to configure this interface. It is an integer between 0 and 4294967295. OSPF uses areas to limit the routing information routers share. It divides routing information into two types: detailed and summarized. Routers share detailed information only within the same OSPF area. Routers in different OSPF areas share only summarized information. They do not share detailed information. OSPF areas are interface-specific. A router's interfaces can run in separate OSPF areas. Area 0 has a special meaning. OSPF uses it as the backbone area. All OSPF areas must connect with it. It is a compulsory area.
OSPF single-area configuration
OSPF single-area configuration keeps all routers in a single area. Since area 0 is compulsory, a single area OSPF configuration includes only area 0. A multi-area configuration includes more than one OSPF area. This tutorial configures OSPF in a single area.
Enabling OSPF routing
Enabling OSPF requires a process ID. Process ID is locally significant. You can use the same process ID on all routers or choose a different ID on each router. Keep all routers in area 0 and use a different process ID on all routers.
Enabling OSPF Routing on R1
The following commands enable OSPF routing on R1.
Router>enable Router#configure terminal Router(config)#router ospf 1 Router(config-router)#network 10.0.0.0 0.255.255.255 area 0 Router(config-router)#network 20.0.0.0 0.255.255.255 area 0 Router(config-router)#network 30.0.0.0 0.255.255.255 area 0 Router(config-router)#exit Router(config)#exit Router#

Enabling OSPF Routing on R2
The following commands enable OSPF routing on R2.
Router>enable Router#configure terminal Router(config)#router ospf 2 Router(config-router)#network 20.0.0.0 0.255.255.255 area 0 Router(config-router)#network 40.0.0.0 0.255.255.255 area 0 Router(config-router)#exit Router(config)#exit Router#

Enabling OSPF Routing on R3
The following commands enable OSPF routing on R3.
Router>enable Router#configure terminal Router(config)#router ospf 3 Router(config-router)#network 30.0.0.0 0.255.255.255 area 0 Router(config-router)#network 40.0.0.0 0.255.255.255 area 0 Router(config-router)#network 50.0.0.0 0.255.255.255 area 0 Router(config-router)#exit Router(config)#exit Router#

Download Packet Tracer LAB with OSPF Routing
Verifying the OSPF routing
OSPF shares routing information only with neighbors. Use the show ip ospf neighbor command on R1 to verify OSPF neighbors.
The output includes the following fields.
Neighbor ID
This field displays the RID of the neighbor.
State
This field displays the convergency state. An OSPF router goes through seven states to reach convergence. The Full state in this field verifies that the router has reached convergence with the router listed in the neighbor ID field.
Interface
This field displays the local interface connected to the neighbor.
Address
This field displays the IP address of the neighbor.
Dead time
This field displays the dead interval.
The following image shows the output of this command on R2.

The following image shows the output of this command on R3.

Viewing OSPF routes
The show ip route ospf command displays a list of all OSPF routes in the routing table. The following image shows the output of this command on R1.

If multiple routes to a destination exist, OSPF adds only the fastest route to the routing table. If two or more routes have an equal cost, it adds all added to the routing table. It uses them for load balancing. For example, R2 has two equal-cost routes for the network 30.0.0.0/8. It adds both routes to the routing table.

The following image shows the output of the show ip route ospf command on R3.

Testing connectivity between end devices
You can test connectivity between end devices to verify the OSPF configuration on all routers. Send ping requests from the PC to the Server. If it gets replies, it verifies the OSPF configuration. You can also use the tracert command to print the path the data packets take to reach the destination.

R1 is the default gateway for the PC. It has two routes to reach the network 50.0.0.0/8: a direct route and via R2. It forwards data packets through the second route. The first route has a serial and an Ethernet link. The second route has three Ethernet links. A serial link with default bandwidth costs 64. A 100 Mbps Ethernet link with default bandwidth costs 1. The total cost of the first route is 3 (1+1+1). The total cost of the second route is 65 (64+1). OSPF selects the route that has the least cost.
Conclusion
OSPF is a complex routing protocol. It uses numerous terms for its features and functions. This tutorial explains the basic concepts and configuration steps of the OSPF routing protocol. Learning these concept configuration steps helps you implement and manage the OPSF routing protocol on a live network.
By ComputerNetworkingNotes Updated on 2026-05-29