OSPFIntermediate41 min read

What Does OSPF cost Mean?

Reviewed byJohnson Ajibi· Senior Network & Security Engineer · MSc IT Security
On This Page

Quick Definition

OSPF cost is a number assigned to each connection (link) between routers. The number tells the router how 'expensive' it is to use that link. OSPF then chooses the path with the lowest total cost to send data. Think of it like choosing the cheapest toll road for a trip.

Common Commands & Configuration

show ip ospf interface GigabitEthernet0/1

Displays OSPF parameters including the cost assigned to the specified interface. Use this to verify the current cost, interface bandwidth, and whether cost is manually configured.

Common 'show' command for CCNA and Network+. Questions often ask to interpret the output to find the cost value and understand why a particular path is chosen.

ip ospf cost 50

Interface configuration command that manually overrides the default OSPF cost on that interface to 50. Use when you want to influence path selection without changing bandwidth.

Key command for traffic engineering. Exams test whether the manual cost overrides the automatic calculation. Remember that the cost range is 1-65535.

auto-cost reference-bandwidth 10000

Global OSPF process configuration command that changes the reference bandwidth to 10000 Mbps (10 Gbps). All interfaces then have cost = 10000000000 / bandwidth.

Critical for modern networks. Exams test that this command forces all routers in the area to have the same reference to avoid metric inconsistency. Often seen in CCNP and CCIE.

bandwidth 100000

Interface command that sets the interface's bandwidth to 100,000 Kbps (100 Mbps). This influences OSPF cost calculation without affecting actual physical speed.

Trick alert! This command only changes routing metric, not link speed. Common exam scenario: a serial link at 1.544 Mbps but bandwidth set to 2000 Kbps, so cost calculation uses 2000 Kbps.

redistribute ospf 1 metric-type 1 metric 20

Redistributes routes from another protocol into OSPF with a type 1 external metric and a base cost of 20. The total cost for E1 routes includes the internal cost to the ASBR.

Tests understanding of E1 vs E2 cost behavior. Many exam questions ask which route is preferred when E1 and E2 exist with different metrics.

show ip route ospf

Displays the OSPF routing table, including the metric (cost) for each route. Use to verify the path cost and compare routes to the same destination.

Essential for verifying path selection. Questions combine output of this command with 'show ip ospf interface' to diagnose routing issues.

clear ip ospf process

Resets the OSPF process, forcing recalculations including cost-based path selection. Use after changing reference bandwidth or interface costs to immediately apply changes.

Know that after changing cost or reference bandwidth, this command may be needed to converge quickly. But beware – it temporarily disrupts routing.

OSPF cost appears directly in 7exam-style practice questions in Courseiva's question bank — one of the most-tested concepts on Cisco CCNA. Practise them →

Must Know for Exams

OSPF cost is a core topic in several IT certification exams. For the CCNA exam, it is a primary topic, appearing in everything from basic OSPF configuration questions to advanced troubleshooting scenarios. The exam expects you to understand the default cost calculation, how to verify it with 'show ip ospf interface', and how to manually override it with the 'ip ospf cost' command. You must also know how the SPF algorithm uses cost to select the best path and the impact of changing the reference bandwidth on a multi-vendor network.

For Network+, the concept of OSPF cost is covered under routing protocols and metrics. You need to understand that OSPF uses a metric based on bandwidth (cost) as opposed to hop count (RIP). Questions may ask you to compare OSPF to other protocols or to interpret a simple topology to determine which path OSPF would choose based on given costs.

In the context of cloud exams like AWS SAA and AZ-104, OSPF cost is more of a supporting concept. While these exams focus on cloud networking services (like AWS Direct Connect or Azure ExpressRoute), they often assume you understand how on-premises routing protocols like OSPF interact with these services. For example, you might need to know how OSPF cost influences path selection when connecting your on-premises network to the cloud via multiple VPN tunnels or Direct Connect circuits.

For Security+ and Google ACE, OSPF cost is light supporting knowledge. It may appear in questions about network segmentation, secure routing, or default routes. However, being able to discuss OSPF cost intelligently shows depth of understanding. In all exams, the ability to explain why one path is chosen over another, and what effect changing the cost has, separates simple memorization from genuine competence. Therefore, mastering OSPF cost is not just about passing a test; it is about building a foundation for a career in networking and cloud infrastructure.

Simple Meaning

Imagine you are planning a road trip from your home to a beach. You have a map with several possible routes. Each road has different characteristics: some are short but have many stoplights, some are long but are smooth highways, and others have tolls that cost money. To decide which route is best, you might consider not just distance but also time, comfort, and cost. This is similar to how OSPF (Open Shortest Path First) routing works in computer networks.

In a network, routers are like intersections, and the connections between them are like roads. Data packets need to travel from one router to another to reach their destination, like a computer or a server. Just like you want to choose the best road trip route, routers need to choose the best path for data. OSPF uses a value called 'cost' to represent how 'good' or 'bad' a particular connection (link) is. The lower the cost, the better the link.

How is this cost calculated? The default way OSPF calculates the cost is based on the bandwidth of the link. Bandwidth is like the number of lanes on a highway. A highway with many lanes (higher bandwidth) can carry more cars (data) at higher speeds, so it has a lower cost. A narrow, winding road (lower bandwidth) will have a higher cost because it is slower and can carry less traffic. The formula is: Cost = Reference Bandwidth / Interface Bandwidth. The 'Reference Bandwidth' is a standard value set by the network administrator, often 100 Mbps or 1 Gbps.

For example, a Fast Ethernet link (100 Mbps) would have a default OSPF cost of 1 (if the reference bandwidth is 100 Mbps). A slower T1 link (1.544 Mbps) would have a much higher cost, around 64. This means OSPF will strongly prefer sending data over the Fast Ethernet link because its path cost is lower.

However, the network administrator is not stuck with these automatic costs. They can manually change the cost on any link. This is like a road manager deciding to add a toll to a certain highway to discourage its use, or improving a dirt road to make it a priority route. By adjusting costs, network engineers can control traffic flow, balance load across multiple paths, or ensure that critical data takes a specific route. OSPF then runs an algorithm called Shortest Path First (SPF), which calculates all possible paths to a destination and selects the one with the lowest cumulative cost. This is the core of OSPF routing and why understanding cost is essential for network design and troubleshooting.

Full Technical Definition

OSPF cost is a dimensionless metric assigned to each OSPF-enabled interface on a router. It is used by the Shortest Path First (SPF) algorithm, also known as Dijkstra's algorithm, to compute the best path to a destination within an OSPF area. The total cost of a route is the sum of the costs of all outgoing interfaces along that path. OSPF selects the route with the lowest cumulative cost as the best path to a destination and installs it in the routing table.

By default, Cisco IOS calculates the OSPF cost using the formula: Cost = Reference Bandwidth / Interface Bandwidth. The default Reference Bandwidth is 100 Mbps. This formula produces a cost of 1 for a 100 Mbps Fast Ethernet interface, 10 for a 10 Mbps Ethernet, and 65 for a 1.544 Mbps T1 serial link. However, with modern high-speed interfaces like Gigabit Ethernet (1000 Mbps) and 10 Gigabit Ethernet, using the default Reference Bandwidth of 100 Mbps would result in fractional costs (e.g., 0.1 for 1 Gbps), which are not supported. To avoid this, network administrators commonly use the command 'auto-cost reference-bandwidth' to set a higher reference value, such as 1000 Mbps or 10,000 Mbps, ensuring all interfaces have integer cost values greater than or equal to 1.

It is critical to understand that OSPF cost is a per-interface metric. It is not globally defined for a router but is configured or automatically derived for each individual interface. The cost can be manually overridden using the interface configuration command 'ip ospf cost <value>'. Manual configuration gives administrators fine-grained control over path selection. For instance, a higher-cost link can be deliberately preferred for backup traffic by setting its cost lower than the primary path, or a link can be forced to be a backup by assigning it a very high cost.

OSPF cost is a link-state metric. Unlike distance-vector protocols (like RIP which use hop count), OSPF's cost reflects the actual characteristics of the link, such as bandwidth, delay, or reliability. This makes it a more accurate and efficient metric for modern networks. OSPF Version 2 (for IPv4) and OSPF Version 3 (for IPv6) both use cost as their metric. The SPF algorithm recalculates paths whenever there is a topology change, which can be triggered by a link failure, a cost change, or the addition of a new router. Each router maintains a Link State Database (LSDB) that contains all the link-state advertisements (LSAs) from the area. From this database, the SPF algorithm builds a shortest path tree with itself as the root, and the cost to each destination is derived from this tree.

In multi-area OSPF deployments, the cost metric applies within an area. For inter-area routes, the cost from an Area Border Router (ABR) to the destination within that area is advertised into the backbone area (Area 0) and then into other areas. The total cost to an inter-area destination is the cost from the local router to the ABR, plus the cost advertised by the ABR to the destination. For external routes (redistributed from other protocols or different OSPF processes), the cost can be either a Type 1 or Type 2 metric. Type 1 external cost is added to the internal cost of the ASBR (Autonomous System Boundary Router) path, while Type 2 external cost is considered without adding the internal path cost (by default, it is Type 2). Understanding these nuances is critical for exam scenarios, particularly in CCNA and Network+ exams, where questions often ask about path selection based on cost and the impact of manual cost adjustments.

Real-Life Example

Think of OSPF cost like the 'price' of using different roads in a city for a delivery truck. You are the network administrator of a delivery company, and your job is to ensure packages (data) get from the central warehouse (one router) to a customer's house (another router) as quickly and efficiently as possible. Each street (link) has a cost associated with it based on how 'expensive' it is to use.

First, consider a wide, multi-lane freeway (a Gigabit Ethernet link). This freeway allows your truck to drive at high speed with minimal traffic jams. The cost of using this freeway is low, maybe $1 in tolls, because it is fast and efficient. Next, there is a small, two-lane road through a residential area (a 10 Mbps Ethernet link). This road has many stop signs and school zones, making the trip slower and less efficient. The cost here is higher, say $5. Finally, there is a long, winding dirt road (a T1 serial link) that is very slow and bumpy. The cost for this road is $20 because it takes a long time and could damage the packages.

When your delivery truck needs to go from the warehouse to the customer, it will naturally choose the route that costs the least total money. If the freeway goes directly from the warehouse to almost the customer, with a very small residential road at the end, the total cost might be $1 (freeway) + $5 (residential) = $6. If there is a route that uses the freeway most of the way but then a small side street, the cost might be $1 + $2 = $3. The best path is the one with the lowest total cost.

Now, what if you, as the manager, want to control the traffic? You can add 'tolls' to the freeway (increase its cost manually) to force some delivery trucks to take the residential road, perhaps to balance the load and prevent the freeway from being too crowded. Or, you can improve the residential road (decrease its cost) to make it more attractive. This is exactly what network engineers do when they manually configure OSPF cost on interfaces. They control how traffic flows across the network to optimize performance, reliability, and redundancy. If a road becomes blocked due to an accident (link failure), OSPF recalculates and finds the next best path with the new lowest cost, ensuring your packages still get delivered, albeit possibly via a more expensive route.

Why This Term Matters

OSPF cost matters because it directly determines how data flows through a network, which in turn affects application performance, user experience, and network reliability. In a real IT environment, network administrators must ensure that critical services like voice over IP (VoIP), video conferencing, and database access use the best possible paths to minimize latency and jitter. By understanding and tuning OSPF cost, they can design networks that are both efficient and resilient.

For example, in a corporate network with redundant links, a misconfigured cost could cause traffic to traverse a slow, congested backup link instead of a high-speed primary link, leading to poor application performance. Conversely, if costs are set correctly, traffic will naturally flow along the intended paths, and in the event of a failure, OSPF will quickly reroute traffic using the next best path. This allows organizations to implement load balancing (using equal-cost multipath) and provide high availability.

OSPF cost is a fundamental concept for network troubleshooting. When users report slow connectivity, one of the first checks is to verify the OSPF cost on the paths between their device and the server. If the cost is unexpectedly high, it could indicate a link issue, a misconfiguration, or a suboptimal path being chosen. Knowing how to read the OSPF database and identify cost values is a critical skill for any network professional. It is not just a theoretical concept; it is a daily operational tool for ensuring network health and performance.

How It Appears in Exam Questions

Exam questions about OSPF cost typically fall into several patterns. The most common is the 'path selection' scenario. Here, you are given a diagram of routers with interfaces and their bandwidths (or directly given costs) and asked which path OSPF will choose to reach a specific network. For example, Router A has two paths to network X: one via Router B with a cost of 10, and one via Router C with a cost of 5. The answer is the path via Router C. Sometimes the question may involve equal-cost paths, and you need to know that OSPF will load balance across them (ECMP).

Another type is the 'configuration' question. Here, you are shown a partial router configuration and asked to identify or correct a command that affects OSPF cost. For instance, 'Which command would you use to change the OSPF cost on an interface from its default value of 10 to 20?' The correct answer is 'ip ospf cost 20'. You might also encounter questions about the 'auto-cost reference-bandwidth' command and its purpose, especially in networks with Gigabit or 10 Gigabit interfaces.

Troubleshooting questions are also frequent. A scenario describes a network where traffic is taking a suboptimal path, and you must analyze 'show ip ospf database' or 'show ip route' output to identify the issue. For example, the output might show that a router has an OSPF route via a neighbor with a higher cost than expected. This could be due to a manual cost misconfiguration, a mismatch in reference bandwidth, or a link that is running at a lower speed than possible (e.g., a gigabit interface negotiating to 100 Mbps). You would then need to choose the correct fix.

Finally, there are 'multi-vendor' or 'interoperability' questions. OSPF cost is standardized, but different vendors (Cisco, Juniper, Huawei) have different default reference bandwidths. A question might point out that a network has hardware from two vendors and that OSPF is not choosing the expected path. The solution could be to manually set the reference bandwidth consistently across all routers with the 'auto-cost reference-bandwidth' command. Understanding these question patterns helps you focus your study and test preparation.

Practise OSPF cost Questions

Test your understanding with exam-style practice questions.

Practise

Example Scenario

A small company has three routers: R1, R2, and R3, all in the same OSPF area. R1 is connected to the internet and to two internal networks: Network A (10.10.10.0/24) and Network B (10.10.20.0/24). R2 and R3 provide connectivity to the rest of the company. The link between R1 and R2 is a Fast Ethernet link (100 Mbps). The link between R1 and R3 is a slower T1 link (1.544 Mbps). All routers are running OSPF with default settings.

When a user on Network A wants to reach a server on Network B, traffic must go from the server to R2 (or R3) then to R1, then to the destination. But consider a scenario where R2 has a direct link to a server on Network B, and R3 also has a link to the same server. The OSPF cost from R1 to R2's connection to Network B is: cost of R1-R2 link (default 1 for Fast Ethernet) + cost of R2's interface to the server (say 1 for Fast Ethernet) = total cost 2. The path via R3: cost of R1-R3 link (default 64 for T1) + cost of R3's interface to the server (1) = total cost 65. OSPF will choose the path via R2 because its total cost (2) is lower than the path via R3 (65).

Now, imagine the network administrator wants to use the T1 link as a backup only. They could manually increase the OSPF cost on the Fast Ethernet link between R1 and R2 to a very high value, like 100, making the path via R2 less attractive than the path via R3. This would force all traffic to go through R3 during normal operations, but if R3 fails, the cost on R2 would once again be the best (since the alternative path is gone). This scenario demonstrates how OSPF cost directly influences routing decisions and network design.

Common Mistakes

Thinking that OSPF cost is based on hop count like RIP.

OSPF cost is based on bandwidth (or manually configured values), not the number of routers. A path with fewer hops but slower links can have a higher cost than a path with more hops but faster links.

Always consider link bandwidth, not router count. Use the 'show ip route' command to see the actual metric (cost) for each route.

Assuming that higher bandwidth always means lower OSPF cost automatically.

While the default formula uses bandwidth, an administrator can manually override the cost on any interface. A 10 Gbps link might have a manually set cost of 100, making it less preferred than a 1 Gbps link with a cost of 1.

Always check the actual OSPF cost with 'show ip ospf interface'. Do not assume the cost based solely on bandwidth.

Forgetting to change the reference bandwidth in networks with Gigabit or higher interfaces.

With the default reference bandwidth of 100 Mbps, a Gigabit Ethernet interface receives a cost of 0.1, which is not a valid integer. OSPF then defaults to a cost of 1, effectively making all high-speed links appear equal (cost 1). This prevents accurate path selection.

Use the 'auto-cost reference-bandwidth' command to set a value that allows integer costs for all interfaces. For example, set it to 1000 (Mbps) to make a 1 Gbps link cost 1, and a 100 Mbps link cost 10.

Confusing OSPF cost with OSPF priority.

OSPF priority is used in the Designated Router (DR) and Backup Designated Router (BDR) election process on multi-access networks like Ethernet. It has nothing to do with path selection. Cost is the metric used to calculate the shortest path.

Remember: cost is for path selection; priority is for DR/BDR election. They are independent concepts.

Thinking that OSPF cost is only relevant for intra-area routes.

OSPF cost is used for all OSPF routes, including inter-area and external routes. While external routes can have Type 1 or Type 2 metrics, the cost is still a fundamental part of the decision process.

Understand that cost applies to all OSPF routes. For external Type 2 routes, the cost is compared without adding the internal path cost to the ASBR.

Believing that OSPF cost can be set globally for the entire router.

OSPF cost is a per-interface metric. It must be configured individually on each interface. There is no global command to set a single cost for all interfaces.

Always configure cost at the interface level using 'ip ospf cost <value>'.

Exam Trap — Don't Get Fooled

{"trap":"A question shows two paths to a destination, one with a total cost of 20 via Router A and one with a total cost of 25 via Router B. The learner sees that Router A's path has a higher bandwidth link on one segment and assumes it is the better path, ignoring the fact that the other segment in the path might have a very high cost.","why_learners_choose_it":"Learners often focus on a single 'fast' link in the path and forget that OSPF cost is cumulative.

They might also confuse bandwidth with cost, thinking that high bandwidth always means low cost, but if the link's cost is manually set high, it can be the opposite.","how_to_avoid_it":"Always compute the total end-to-end cost. Use the formula: total cost = sum of costs of all interfaces along the path.

Do not assume that one fast link makes the entire path best. Verify with 'show ip route' for the actual metric. Remember that OSPF selects the path with the lowest total cost, not the one with the highest bandwidth on a single segment."

Commonly Confused With

OSPF costvsOSPF Priority

OSPF priority is a number (0-255) used during the Designated Router (DR) and Backup Designated Router (BDR) election process on multi-access networks like Ethernet. It has no role in path selection. OSPF cost is the metric used to choose the best route. Changing priority does not affect which path traffic takes.

Setting priority to 0 on a router means it will never become DR, but that router can still have a low-cost path that OSPF uses to forward traffic.

OSPF costvsEIGRP Metric

EIGRP uses a composite metric based on bandwidth, delay, reliability, load, and MTU (by default, only bandwidth and delay). OSPF cost is simpler: it's just based on bandwidth (or manually set). EIGRP is a Cisco proprietary protocol, while OSPF is an open standard. In exams, you need to know both, but they are not interchangeable.

Two links: one with high bandwidth and high delay, and another with medium bandwidth and low delay. EIGRP might prefer the medium bandwidth link due to lower delay, while OSPF (default) would prefer the high bandwidth link.

OSPF costvsRIP Metric (Hop Count)

RIP uses hop count as its metric, meaning each router adds 1 to the metric when crossing a router. OSPF cost is far more sophisticated, allowing engineers to differentiate based on link speed and manually assign costs. RIP's simple metric can lead to suboptimal routing in complex networks.

A path that traverses two fast routers (total cost 2 in OSPF) might be preferred by OSPF over a path with one slow router (cost 10), whereas RIP would choose the one-hop path regardless of speed.

OSPF costvsBGP Path Attributes (AS Path, Local Pref)

BGP uses many attributes like AS path length, local preference, and MED to make routing decisions between autonomous systems. OSPF cost is used only within a single autonomous system (IGP). BGP is an EGP, and its decision process is more complex and based on policies, not simple link cost.

A company running OSPF internally uses cost to choose paths inside the company. When connecting to the internet, BGP may use a shorter AS path to choose one ISP over another, ignoring the internal OSPF cost.

OSPF costvsIS-IS Metric

IS-IS uses a metric that is similar to OSPF cost, but by default the metric is a fixed value (typically 10) on all interfaces. Network administrators can change it manually. Both are link-state protocols, but IS-IS is often used in large service provider networks. OSPF has more features like virtual links and NSSA areas.

In an IS-IS network with default metrics, all links cost 10, making path selection purely hop-count based, unlike OSPF's bandwidth-based default.

Step-by-Step Breakdown

1

OSPF Hello and Adjacency Formation

Before OSPF can compute paths, routers must discover each other. They send Hello packets to neighboring routers, and if parameters match (like area ID, authentication, network mask), they form an adjacency. This step sets up the neighbor relationship necessary to exchange routing information.

2

Exchange of Link-State Advertisements (LSAs)

Once adjacencies are formed, routers exchange LSAs. Each LSA describes the state of a router's interfaces, including its OSPF cost, connected networks, and neighbor relationships. This information is flooded throughout the area, so every router learns the complete topology.

3

Building the Link-State Database (LSDB)

Each router collects all received LSAs and stores them in its Link-State Database. The LSDB represents the complete map of the network, including all routers and their link costs. All routers in the same area should have identical LSDBs, ensuring consistent path calculation.

4

Running the Shortest Path First (SPF) Algorithm

Using Dijkstra's algorithm, each router calculates the shortest path to every destination in its area. The algorithm treats the router itself as the root of a tree and iteratively adds branches (neighbors) with the lowest cumulative cost. This step produces the shortest path tree (SPT).

5

Determining Best Path Based on Cumulative Cost

From the SPT, the router identifies the best path to each destination network. The best path is the one with the lowest total cost, which is the sum of the costs of all outgoing interfaces along that path. The router then installs this path in its routing table with the metric set to the total cost.

6

Populating the Routing Table

The router uses the best path from the SPF calculation to update its routing table. Each entry includes the destination network, the next-hop IP address, the outgoing interface, and the OSPF cost. The routing table is used for actual packet forwarding.

7

Propagation of Topology Changes

If a link fails, a new router is added, or a cost is changed, the router detecting the change originates a new LSA. This LSA is flooded to all other routers in the area. Each router then reruns the SPF algorithm to recalculate paths, ensuring the network adapts to changes. The cost updates directly affect the new best path.

Practical Mini-Lesson

Understanding OSPF cost is not just about the formula; it is about how to apply it in real-world network design and troubleshooting. As a network professional, you will often need to influence traffic flow without physically changing link speeds. The primary tool for this is manual cost configuration.

For instance, imagine you have two links between two routers, a primary Gigabit Ethernet (GE) link and a backup Fast Ethernet (FE) link. With default costs (GE cost 1, FE cost 10), all traffic will go over the GE link. But what if you want to use both links simultaneously for load balancing? OSPF supports equal-cost multipath (ECMP) only when the total cost to the destination is equal. Since GE cost 1 and FE cost 10 are not equal, ECMP will not happen. To make them equal, you can manually set the cost on the GE link to 10, matching the FE link. Now both paths have a cost of 10, and OSPF will load balance traffic across both. However, this defeats the purpose of having a faster primary link. So you need to consider trade-offs.

Another practical use is influencing incoming traffic from a remote site. If a remote branch has two WAN connections to the headquarters, you can set the OSPF cost on the headquarters routers to influence which link the branch prefers to send traffic. For example, to make the branch prefer the link with higher bandwidth, you set that link's cost lower on the headquarters router.

Troubleshooting is where cost knowledge becomes critical. If a user reports slow access to a server, check the OSPF cost on the path. Use commands like 'show ip route <destination>' to see the metric. If the metric is unexpectedly high, examine the OSPF database with 'show ip ospf database' to see if a link has a higher cost than expected. Maybe a Gigabit interface negotiated to 100 Mbps, causing the cost to jump from 1 to 10. Or maybe someone accidentally set a manual cost on an interface. The fix could be as simple as resetting the interface, correcting the manual configuration, or adjusting the reference bandwidth.

A common mistake in production is forgetting to apply consistent reference bandwidth on all OSPF routers. If one router uses 100 Mbps reference, and another uses 1000 Mbps, then a 1 Gbps link will have cost 1 on the first router (since 100/1000 = 0.1, rounded to 1) and cost 1 on the second router (since 1000/1000 = 1). But a 100 Mbps link will have cost 1 on the first and 10 on the second. This inconsistency can cause asymmetric routing and suboptimal paths. Always set 'auto-cost reference-bandwidth' to the same value on all routers.

Finally, in cloud contexts, when connecting on-premises to AWS or Azure via VPN or Direct Connect, OSPF is often used to exchange routes. The cost you assign to the cloud connection can determine whether traffic from your on-premises network uses the VPN or Direct Connect. This is a direct application of OSPF cost management in modern hybrid networks.

Understanding OSPF Cost as a Metric

Open Shortest Path First (OSPF) is a link-state routing protocol that uses a metric called "cost" to determine the best path to a destination network. Unlike distance-vector protocols that rely on hop count or bandwidth alone, OSPF cost is an inverse measure of interface bandwidth – the higher the bandwidth, the lower the cost. The default formula used by Cisco IOS is cost = 10^8 / bandwidth in bps. For example, a FastEthernet interface operating at 100 Mbps has a default cost of 1 (100,000,000 / 100,000,000). A classic 10 Mbps Ethernet link would have a cost of 10 (100,000,000 / 10,000,000). This design ensures that OSPF naturally prefers higher-speed links over slower ones, preventing suboptimal routing.

OSPF cost is calculated per interface and is cumulative along a path. When a router receives a Link State Advertisement (LSA) from a neighbor, it adds the cost of the outgoing interface to the cost advertised by the neighbor. The sum of these costs across all interfaces from source to destination constitutes the total path cost. The Shortest Path First (SPF) algorithm, also known as Dijkstra's algorithm, then selects the path with the lowest total cost. It is critical to understand that cost is one-way; the cost from Router A to Router B may differ from the cost from Router B to Router A if their interface speeds are different.

A common misconception is that OSPF cost is dynamic. In fact, OSPF cost is a static value assigned to an interface, typically based on the interface's configured bandwidth. If the interface bandwidth changes due to autonegotiation or manual configuration, the cost does not automatically update unless the interface is reset or the OSPF process is restarted. However, the "bandwidth" command influences the cost indirectly. Network engineers often manually adjust cost using the "ip ospf cost" command for traffic engineering, load balancing, or to enforce a specific path despite higher bandwidth links being available. This is particularly useful in scenarios where you want to route traffic over a less congested link or avoid a link that is administratively preferred but unstable.

In exam contexts, especially for CCNA and Network+, understanding the default cost calculation and how to override it is essential. OSPF cost is a 16-bit value ranging from 1 to 65,535. A cost of 0 is reserved for directly connected networks. If the calculated cost exceeds 65,535 (which can happen on very low-bandwidth links using the default reference bandwidth), OSPF will assign the maximum value of 65,535. To handle modern high-speed links (e.g., 1 Gbps, 10 Gbps), engineers commonly adjust the reference bandwidth using the "auto-cost reference-bandwidth" command to avoid all high-speed links having a cost of 1, which would defeat the purpose of metric differentiation.

Exam questions often test the candidate's ability to identify the correct cost for a given interface, interpret show commands that output cost values, and troubleshoot routing loops caused by inconsistent cost configurations. For example, if you see a router preferring a 1.544 Mbps T1 link over a 100 Mbps FastEthernet link, the likely cause is an incorrectly configured cost on the FastEthernet interface (e.g., manually set to a high value) or a mismatch in reference bandwidth between routers. Understanding these fundamentals is the first step toward mastering OSPF path selection in real-world networks and certification exams.

Tuning OSPF Cost with Reference Bandwidth and Manual Configuration

The default OSPF cost formula using a reference bandwidth of 100 Mbps was adequate when FastEthernet was the fastest common interface. However, modern networks widely use GigabitEthernet (1 Gbps), 10 GigabitEthernet, and even faster links. With the default reference, a 1 Gbps link would have a cost of 0.1, which is rounded down to 1, and a 10 Gbps link also gets a cost of 1. This makes all links above 100 Mbps indistinguishable to OSPF, leading to equal-cost multipath (ECMP) when different-speed high-bandwidth links exist. To fix this, network administrators use the OSPF process-level command "auto-cost reference-bandwidth" to set a higher reference value, typically 10,000 Mbps (10 Gbps) or higher. For instance, "auto-cost reference-bandwidth 10000" sets the reference to 10 Gbps, so a 1 Gbps link now has a cost of 10, and a 10 Gbps link has a cost of 1. This restores meaningful metric hierarchy.

Manual cost configuration is another powerful tuning method. Using the interface-level command "ip ospf cost <value>", an engineer can override the calculated cost entirely. This is useful for traffic engineering, such as forcing traffic away from a high-bandwidth but unreliable satellite link toward a lower-bandwidth but stable fiber link. Manual cost can also be used to implement policy-based routing within OSPF without using route maps or PBR (Policy-Based Routing). For example, setting a cost of 100 on a link you want as a backup ensures it is never preferred unless the primary link fails. This is common in hub-and-spoke topologies or when using OSPF in conjunction with MPLS or VPNs.

When tuning costs, consistency across the OSPF domain is critical. If routers use different reference bandwidths, the computed path costs become inconsistent, potentially causing routing loops or suboptimal routing. For example, Router A with reference bandwidth 100 Mbps sees a GigabitEthernet link as cost 1, while Router B with reference bandwidth 10,000 Mbps sees the same link as cost 10. The path costs from A to a remote network through B would not match the costs from B back to A, leading to routing asymmetry. While OSPF itself does not mandate symmetric costs, inconsistent costs can cause unexpected behavior during SPF calculations and make troubleshooting difficult.

Exam questions frequently ask about the consequences of mismatched reference bandwidths or the effect of the "auto-cost reference-bandwidth" command. For example, a CCNA exam might present a scenario where two routers are connected via a 1 Gbps link, but one router has default reference and the other has reference set to 10000. The candidate must identify that the cost advertised by each router for that link will differ, leading to incorrect SPF decisions. Another common question is calculating the cost for a 100 Mbps link when the reference bandwidth is set to 1000 Gbps (1,000,000 Mbps), the answer would be 10,000 (1,000,000 / 100), but this exceeds 65,535, so it caps at 65,535.

In advanced scenarios like those seen in CCIE or AWS Advanced Networking exams, candidates must understand how to incorporate OSPF cost tuning into larger network designs, including route summarization and redistribution. For the AZ-104 or Google ACE exams, understanding cost tuning is less about the CLI commands and more about how OSPF cost affects hybrid cloud connectivity, for instance, when using AWS Direct Connect versus a VPN backup. In such cases, manipulating OSPF cost on the on-premises router can control which path is preferred for traffic to the cloud VPC. This practical application is a common exam topic for cloud networking roles.

Troubleshooting OSPF Cost Issues in Real Networks

Troubleshooting OSPF cost issues is a frequent task for network administrators and a staple of certification exams. One common problem is suboptimal routing, where traffic takes a slower link even though a faster one is available. The first step is to check the cost on the interfaces. Use "show ip ospf interface" to display the cost assigned to each interface. If you see a FastEthernet interface with cost 10 instead of the expected 1, it may have been manually set or the interface bandwidth may be incorrectly configured (e.g., set to 10 Mbps via the "bandwidth" command). Another possibility is that the reference bandwidth was changed on some routers but not others. Use "show ip protocols" to see the configured reference bandwidth for the OSPF process.

Another common issue is routing loops when redistributing routes from another protocol into OSPF. If the redistributed routes have inconsistent administrative distances or metrics, OSPF cost can cause unexpected path selection. For instance, if you redistribute a static route into OSPF with a type 5 LSA, the cost is set to 20 by default (for external type 2 routes) or can be manually specified. If two routers redistribute the same network but with different costs, routers may oscillate between paths. The solution is to ensure consistent metric assignment during redistribution, often using route maps to set the OSPF cost explicitly.

A less obvious issue is the "max-cost" problem. OSPF has a maximum individual link cost of 65,535. If an interface's calculated cost exceeds this (e.g., a 56 kbps serial link with default reference: 100,000,000 / 56,000 = 1785.7, which is fine, but with reference bandwidth set to 10,000,000,000, the cost would be 178,571, exceeding the max), OSPF assigns the maximum cost. This can cause the link to be effectively ignored or become a last-resort path, which may not be the intended behavior. The troubleshooting step is to verify the reference bandwidth and interface bandwidth, and either lower the reference or manually set a reasonable cost using "ip ospf cost".

In exam labs, a classic troubleshooting question involves two routers connected via a serial link. Router A has interface bandwidth set to 64 kbps, while Router B has it set to 128 kbps. Although they are physically the same link, the cost calculated by each router will differ, causing asymmetric routing. The candidate must identify the mismatch and correct the bandwidth setting to match. Another scenario: after configuring a new Ethernet link, OSPF neighbors form but the network behind the new router is reachable via a slower path. The candidate should suspect that the cost on the Ethernet interface (or its bandwidth) is set incorrectly, and use "show ip route" and "show ip ospf interface" to diagnose.

For hybrid cloud exams like AWS SAA or AZ-104, OSPF cost troubleshooting extends to VPN and Direct Connect interactions. For example, if an on-premises router prefers the VPN backup over Direct Connect for certain prefixes, the candidate must check the OSPF cost on the Direct Connect interface or the BGP attributes redistributed into OSPF. In many cases, the Direct Connect router advertises a high cost, making the VPN path appear better. Adjusting the cost on the Direct Connect router or setting a lower administrative distance can resolve the issue. These real-world scenarios mirror what you will encounter in production networks and are frequently tested in advanced certifications.

Advanced OSPF Cost Implications and Exam Strategies

Beyond basic cost calculation, OSPF cost has several nuanced behaviors that are critical for high-stakes exams and real-world network design. One important concept is that OSPF cost is used not only for internal routes but also for external routes. Type 1 external routes (E1) add the internal cost from the ASBR to the external metric, while Type 2 (E2) external routes keep only the external metric unless the cost to the ASBR is higher than the external metric. A common exam trick is to ask which path is preferred when two routes exist: one E1 with cost 150 (internal 50 + external 100) and one E2 with cost 100. Because E2 defaults are compared first, if the external metric of the E2 is lower (100 < 150), the E2 path is chosen regardless of internal cost. This catches many students who assume E1 is always preferred.

Another advanced concept is the use of OSPF cost in Virtual Link configurations. When a router acts as a transit router in a virtual link, the cost of the virtual link is set to the maximum cost of the path in the transit area. This can cause unexpected path choices if the transit area has a long path with high costs. Engineers can manipulate the cost on the interface that leads to the virtual link endpoint to influence the virtual link's metric, but this is rarely documented and often a point of confusion. A-plus and Security+ exams may not cover this depth, but CCNA, CCNP, and AWS Professional level exams do.

In multi-area OSPF designs, cost plays a role in route selection between areas. Inter-area routes (type 3 LSAs) carry the cost from the ABR to the destination network. If two ABRs advertise the same network, the router will choose the route with the lowest cost to the ABR plus the cost advertised by the ABR. This means that the metric for an inter-area route is the sum of the cost from the local router to the ABR and the cost from the ABR to the destination. Understanding this is vital for designing scalable OSPF networks and for answering exam questions that present a topology with multiple ABRs.

Exam strategies for OSPF cost include memorizing the default cost for common interface types: 10 Mbps Ethernet = 10, 100 Mbps FastEthernet = 1, 1 Gbps GigabitEthernet = 1 (with default reference, but 10 with reference 10000), T1 (1.544 Mbps) = 64 (since 100/1.544 = 64.8, rounded to 64). Many exam questions expect you to calculate these quickly. Know that the "bandwidth" command on serial interfaces does not affect actual link speed but only influences routing metrics. This is a classic trick: the candidate sees a serial link running at 1.5 Mbps but the bandwidth is set to 2000 Kbps, so the OSPF cost will be based on 2000 Kbps, not the actual speed.

For the Google ACE and AZ-104 exams, cost considerations extend to cloud networking. For example, when connecting an on-premises network to Google Cloud via Cloud VPN and Dedicated Interconnect, OSPF cost on the customer router can be used to prefer Interconnect over VPN. Cloud routers support setting cost metrics, and understanding how to use OSPF cost to control traffic flow in these hybrid environments is a direct exam topic. Similarly, AWS Direct Connect supports BGP, but when routing back into an OSPF domain, the redistribution cost must be carefully managed.

Finally, a common exam mini-game involves identifying why a router chooses a path that seems incorrect. The candidate must consider all OSPF path selection rules: first, prefer intra-area (O) over inter-area (O IA) over external (E1/E2). If both routes are the same type, compare cost. If costs are equal, load-balance. If costs are equal but load-balancing not working, check the routing table and OSPF database for differences. Armed with these strategies, you can conquer any OSPF cost question on the CCNA, Network+, or cloud exams.

Troubleshooting Clues

Suboptimal routing with slower link preferred over faster link

Symptom: Traffic to a remote network takes a T1 link (1.5 Mbps) instead of a GigabitEthernet link available in the topology.

The GigabitEthernet interface likely has a manually configured high cost, or its bandwidth is incorrectly set to a low value. Alternatively, the reference bandwidth might be inconsistent across routers.

Exam clue: Exam questions often show a scenario where a high-speed link has a higher cost than a slow link; the candidate must check the cost on the high-speed interface or the reference bandwidth.

Equal-cost multipath not working as expected

Symptom: Two links to the same destination have different bandwidths (e.g., 100 Mbps and 1 Gbps) but OSPF treats them as equal, or load-balancing is not happening.

With default reference bandwidth (100 Mbps), both links may have cost 1 (100 Mbps / 100 Mbps = 1, 1 Gbps / 100 Mbps = 10, but cost calculated as 100/1000 = 0.1 => 1 after rounding). Thus they appear equal, but if load-balancing is not seen, check if both routes are OSPF intra-area and have same cost.

Exam clue: Candidates must understand that defaults cause equal cost for many high-speed links. Questions may ask why a 1 Gbps and 10 Gbps link are equal cost; answer is the reference bandwidth is too low.

OSPF route not showing in routing table after neighbor adjacency

Symptom: Two routers form a full adjacency (state FULL), but one router does not install the other's routes in its routing table.

Possible cause: received LSA has cost that is too high (e.g., 65535) making the path unattractive, or the LSA has a cost that exceeds the best existing path. Alternatively, a route could be suppressed by a higher administrative distance or route filtering.

Exam clue: Exams test that OSPF route installation is based on cost. If a route has cost 65535 (max), it may not be installed if a lower-cost route exists from another source.

Asymmetric routing between two routers

Symptom: Traffic from Router A to a network goes through link X, but return traffic from Router B goes through link Y, causing connectivity issues or high latency.

This often occurs when OSPF costs are not symmetric: Router A's cost for link varies from Router B's cost for the same link. For example, if A's bandwidth is configured as 100 Mbps and B's as 10 Mbps on the same link, costs differ.

Exam clue: Classic CCNA troubleshooting: two routers connected via serial; one has bandwidth set to 64 kbps, the other to 128 kbps. The candidate must identify the mismatch by comparing costs using 'show ip ospf interface'.

Traffic not switching to backup link when primary fails

Symptom: After primary interface goes down, OSPF does not fail over to the backup link for a long time or not at all.

Possible reasons: backup interface has a cost set to a very high value (e.g., 65535), causing OSPF to not use it as a backup. Or the backup link is a different OSPF area and the inter-area route to the primary destination is hidden by a summary with higher cost.

Exam clue: Exams often ask why a backup link fails to take over; answer may involve manual cost being too high or the backup link being in a different area with a higher LSA cost.

Redistributed routes have unexpected metric in OSPF database

Symptom: Routes redistributed from EIGRP or BGP into OSPF show a metric of 20 (default E2) instead of the intended value, causing incorrect path selection.

By default, redistributed external routes in OSPF are Type 2 with metric 20 unless explicitly changed. The redistribute command's 'metric' and 'metric-type' options control this. If not set, the metric defaults may not be desired.

Exam clue: Common exam question: 'What is the default metric for routes redistributed into OSPF?' Answer: 20 for E2. Also, know that type E1 includes internal cost, which can change the effective metric.

Reference bandwidth mismatch between routers in same area

Symptom: Routes from one router appear with different costs than expected, leading to routing loops or suboptimal paths.

Each router uses its own reference bandwidth for cost calculation. If they differ, the same physical link may have different costs on each router, causing SPF to compute asymmetric paths.

Exam clue: Exams present a scenario where Router A has reference 100 and Router B has reference 10000. The candidate must determine that one router sees the link as cost 1, the other as cost 10, leading to asymmetric routing.

Memory Tip

Think 'C for Cost, C for Cumulative', OSPF cost is a cumulative metric where you add up the costs of all outgoing interfaces along the path, and the path with the lowest total cost wins.

Learn This Topic Fully

This glossary page explains what OSPF cost means. For a complete lesson with labs and practice, see the topic guide.

Covered in These Exams

Current Exam Context

Current exam versions that test this topic — use these objectives when studying.

Related Glossary Terms

Quick Knowledge Check

1.A network engineer configures a new GigabitEthernet interface in an OSPF network with default settings. What is the OSPF cost of this interface?

2.Which command can be used to change the OSPF cost of a FastEthernet interface to 50 to influence path selection?

3.Two routers are connected via a serial link. Router A has bandwidth set to 128 kbps, Router B has bandwidth set to 64 kbps. Both use default reference bandwidth. What issue might occur?

4.In a multi-area OSPF network, an ABR sends a type 3 LSA for a network in another area. What cost does the ABR advertise in the LSA?