# OSPF metric

> Source: Courseiva IT Certification Glossary — https://courseiva.com/glossary/ospf-metric

## Quick definition

OSPF uses a metric called cost to decide the best path for data to travel. The cost is usually based on the bandwidth of the link, with lower costs being better. When multiple paths exist, OSPF picks the one with the lowest total cost.

## Simple meaning

Imagine you are planning a road trip and you want to get to your destination as quickly as possible. You have several different routes to choose from. Some routes have highways with high speed limits, while others have slow, winding roads. OSPF works like a GPS that calculates the best route for data. In this system, each road has a number that represents its 'cost' – the higher the cost, the slower or less desirable that road is. OSPF adds up all the costs for each possible route from start to finish, and then it chooses the route with the smallest total cost.

Now, what determines that cost? In OSPF, the cost is usually calculated based on the bandwidth of the link. A high-bandwidth link, like a fiber optic cable, gets a low cost, much like a wide, fast highway would get a low travel time. A low-bandwidth link, like an old telephone line, gets a high cost. OSPF's formula is simple: it divides a reference bandwidth (typically 100 Mbps) by the actual bandwidth of the link. So for a 100 Mbps link, the cost is 1. For a 10 Mbps link, the cost is 10. This makes OSPF's metric 'cost' directly tied to speed.

But OSPF does not just look at one road. It looks at the entire journey. Every router along the way adds its own cost to the total. OSPF then compares all possible paths and selects the one with the lowest total cost. This is called the Shortest Path First algorithm. It is important to understand that OSPF is not just choosing the fewest number of hops (the number of routers data passes through). It cares about the quality of each link. A path with three fast fiber links might be much better than a path with just two slow DSL links. OSPF knows this because it calculates cost based on bandwidth, not just distance.

In a network, OSPF routers share information about their links (and the cost of those links) with each other. Each router then builds a complete map of the network. This map is called the link-state database. From this map, the router runs the SPF algorithm to calculate the best path to every destination. The metric is fundamental because it is what allows OSPF to make intelligent routing decisions. Without the metric, OSPF would just guess which way to send data. With the metric, it can optimize for speed, reliability, or whatever the network admin wants. In practice, network administrators can also manually override the cost on a link to influence routing choices, giving them fine control over traffic flow.

## Technical definition

Open Shortest Path First (OSPF) is a link-state routing protocol that uses a metric value called cost to determine the best path to a destination network. Unlike distance-vector protocols like RIP, which use hop count, OSPF directly considers the bandwidth of each link in its path calculation. The OSPF metric is dimensionless and is defined in RFC 2328 for OSPFv2 (IPv4) and RFC 5340 for OSPFv3 (IPv6). The default cost calculation uses the formula: Cost = Reference Bandwidth / Interface Bandwidth, where the default reference bandwidth is 100 Mbps on most Cisco devices.

When OSPF is enabled on a router interface, the cost is automatically assigned based on the interface's bandwidth setting. For example, a FastEthernet interface with a bandwidth of 100,000 kbps gets a default cost of 1. A T1 link (1.544 Mbps) gets a cost of 64 (100/1.544 rounded down). A 10 Mbps Ethernet link gets a cost of 10. However, network engineers can manually override the cost using the 'ip ospf cost' command in Cisco IOS or equivalent commands on other vendors. This manual override allows fine-tuning of path selection for traffic engineering or policy purposes.

The OSPF metric is additive along the path. Each router in the path contributes its own cost for the interface it uses to forward traffic. The total cost from the source router to the destination network is the sum of the outgoing interface costs on each router along the path. OSPF uses the Shortest Path First (SPF) algorithm, developed by Edsger Dijkstra, to compute the lowest-cost path. The SPF algorithm runs on the link-state database, which contains all the topological information about the network. When a change occurs, such as a link going down or a new link being added, the affected routers flood updated Link State Advertisements (LSAs) to all other routers in the same OSPF area. Each router then recalculates its routing table using the SPF algorithm.

OSPF supports multiple path types, each with a different cost basis. For intra-area routes (within the same area), the cost is purely based on the interface costs. For inter-area routes, the cost includes the cost to reach the area border router (ABR) plus the cost from the ABR to the destination. For external routes redistributed into OSPF from another protocol, a metric type can be configured. Type 1 external metrics include the OSPF cost to reach the ASBR plus the redistributed metric, while Type 2 external metrics only use the redistributed metric, ignoring internal OSPF costs.

Cost equivalency is important in OSPF. If multiple paths have the same total cost to the same destination, OSPF can load-balance across up to four paths by default (or up to 16 on some implementations). This is called Equal-Cost Multi-Path (ECMP) routing. The number of equal-cost paths can be adjusted with the 'maximum-paths' command. In large networks, the reference bandwidth may need adjustment because 100 Mbps is too low for modern 1 Gbps or 10 Gbps links, which would all get a cost of 1, making them indistinguishable. Administrators set the reference bandwidth to a higher value, such as 1 Gbps or 10 Gbps, to differentiate higher-speed links.

OSPF version 2 (for IPv4) and version 3 (for IPv6) use the same metric concept, though OSPFv3 has a slightly different LSA structure. Both versions store the metric as a 16-bit unsigned integer, meaning the maximum cost for a single link is 65,535. The total path cost is also limited to 16 bits, so extremely long paths can be problematic. In practice, the metric is flexible enough for most enterprise networks. When designing OSPF networks, administrators must consider the metric to ensure optimal routing, avoid suboptimal path selection, and prevent routing loops. The metric is also crucial in MPLS Traffic Engineering extensions to OSPF, where it is used alongside other attributes like bandwidth reservation.

## Real-life example

Think of the OSPF metric like the total travel time for a package delivery service. Suppose you work for a courier company that has to deliver a package from New York to Los Angeles. Your company has several different routes that the delivery trucks can take. Each route is made up of a series of roads, each with its own speed limit and traffic conditions. The OSPF metric is like the total estimated travel time for a truck to travel that entire route.

Let's break it down. Imagine one route uses mostly interstate highways with a speed limit of 70 miles per hour. Another route uses smaller state roads with a speed limit of 35 miles per hour. A third route mixes a short local road that is usually congested with a fast highway. Your company wants to choose the route that gets the package there the fastest. The 'cost' OSPF assigns to each road segment is like the time it takes to travel that segment. A high-speed highway gets a low cost (maybe 10 minutes), while a slow city street gets a high cost (maybe 45 minutes). The total cost of the route is the sum of all the segment times from New York to LA. OSPF's algorithm picks the route with the smallest total travel time.

Mapping to the IT concept: In a computer network, the 'roads' are the cables (like Ethernet, fiber, or DSL) connecting routers. The 'speed limit' is the bandwidth of each link. A high-bandwidth fiber link has a low OSPF cost, just like a highway has a low travel time per mile. A low-bandwidth link has a high OSPF cost. The 'delivery truck' is the data packets being sent from one network to another. The routers act like the navigation system, choosing which way to send the packet based on the total cost to the destination.

Now, what if a road is closed for construction? In the network, if a link fails, OSPF recalculates the map and finds another route. The new route might have a higher total cost (longer travel time), but it still works. Also, a savvy network administrator can manually adjust the cost of an interface, like adding a toll to a road to discourage traffic. For example, if you want traffic to prefer a satellite link over a slower DSL link, you can set the satellite link's cost to a low number. This kind of control is powerful for managing network performance and reliability. So just like a package delivery dispatcher wants the fastest path for every delivery, OSPF uses its metric to find the fastest path for every packet.

## Why it matters

The OSPF metric matters because it directly determines the efficiency and performance of routing in OSPF-based networks. Without a proper understanding of metrics, network administrators risk suboptimal traffic flow, where data might travel over slow or congested links when faster alternatives exist. This can lead to increased latency, packet loss, and poor user experience for applications like VoIP, video streaming, or real-time financial transactions.

In practical IT, the metric is the tool that enables traffic engineering. For example, if a network has redundant links to the internet, a network engineer can manipulate the OSPF metric to ensure that voice traffic uses a low-latency fiber link while bulk data transfers use a higher-latency but cheaper satellite link. This level of control is impossible without understanding how OSPF calculates and uses its metric. In large enterprise networks, the default metric based on bandwidth may not reflect actual network conditions. Links may have the same bandwidth but different utilization or reliability. Administrators can override the metric to balance load or prioritize certain paths.

From a troubleshooting perspective, many performance issues in OSPF networks can be traced back to metric misconfigurations. A classic problem occurs when a high-bandwidth link gets a cost of 1 because of the default reference bandwidth, forcing OSPF to treat a 1 Gbps link the same as a 100 Mbps link. This can lead to unexpected load balancing or suboptimal routing when the administrator expects only the fastest link to be used. Adjusting the reference bandwidth or manually setting costs solves this. The OSPF metric is not just an abstract number; it is a powerful lever that controls the flow of data across the entire network. Mastery of metrics is essential for anyone managing OSPF in production environments.

## Why it matters in exams

The OSPF metric is a core concept in the CCNA and Network+ exams, and it appears in varying depth in AWS, Azure, and Google Cloud exams. For the CCNA (200-301), understanding OSPF cost calculation is explicitly listed in the exam objectives under 'Routing Technologies'. You need to know the default cost formula, how to override it, and how OSPF selects paths. Multiple-choice questions often give a network diagram with link speeds and ask which path OSPF will choose. Simlet questions might require you to configure the cost on an interface using the 'ip ospf cost' command.

In CompTIA Network+, the OSPF metric is part of the broader understanding of routing protocols. While not as detailed as CCNA, questions test whether you know that OSPF uses cost based on bandwidth (not hop count) and that lower cost is preferred. Troubleshooting scenarios might describe a network where traffic is taking a suboptimal path, and you need to identify that the OSPF metric is misconfigured.

For cloud certifications like AWS SAA (AWS Certified Solutions Architect - Associate), OSPF is not a primary focus, but it appears in the context of Direct Connect and VPN routing. When configuring a virtual private gateway, you may need to set OSPF metrics to influence which path (Direct Connect or VPN) is preferred for failover. Similarly, in Azure (AZ-104), OSPF is used in ExpressRoute circuits for BGP routing, and metrics affect path selection. In Google Cloud ACE, OSPF is used in Cloud Router, and the metric determines which on-premises path is chosen for traffic destined to Google Cloud. The exam objectives for these cloud exams usually ask you to understand how routing protocols influence traffic flow, not to memorize the exact OSPF formula.

Typical question formats include: 'Which OSPF metric value will be assigned to a 1 Gbps link?' (Answer: 1, assuming default 100 Mbps reference bandwidth), or 'If a router has two OSPF routes to network 10.0.0.0/8 with costs 20 and 30, which one will be installed in the routing table?' (Answer: the one with cost 20). More advanced CCNA questions might ask: 'What is the effect of changing the reference bandwidth from 100 to 1000?' The correct answer is that higher-speed links will now have different cost values, allowing better load balancing decisions. Understanding these nuances is crucial for passing the exam.

## How it appears in exam questions

Exam questions about the OSPF metric typically fall into three categories: conceptual, calculation-based, and scenario/troubleshooting.

Conceptual questions are straightforward. For example: 'Which metric does OSPF use to determine the best path?' or 'True or false: OSPF uses hop count as its metric.' The answer is cost (or bandwidth). Another common conceptual question: 'What command is used to manually set the OSPF cost on a Cisco interface?' The answer is 'ip ospf cost'.

Calculation-based questions are very common in CCNA. You might be given a network diagram with three links: Link A has a bandwidth of 100 Mbps, Link B has 1 Gbps, and Link C has 10 Mbps. The question asks: 'What is the OSPF cost for each link?' You need to calculate using the default formula (100 Mbps / link bandwidth). So Link A cost = 1, Link B cost = 1 (because 100/1000 = 0.1, which is rounded to 1), and Link C cost = 10. Then the question might ask: 'Which path will OSPF choose from Router X to Network Y?' The correct answer is the path with the lowest cumulative cost. Often, two paths will have equal costs, and the question then asks about ECMP load balancing.

Scenario-based questions present a real-world problem. For instance: 'A network administrator notices that OSPF is load balancing across a 100 Mbps link and a 1 Gbps link, but the 1 Gbps link is underutilized. What is the most likely cause?' The answer is that the OSPF costs are equal because the default reference bandwidth treats both as cost 1. The solution would be to adjust the reference bandwidth or manually set a different cost on the slower link. Another scenario: 'A new WAN link is added to the OSPF network, but traffic is not using it. What should be checked?' The answer is to verify the OSPF cost on the new link and compare it to existing paths.

Troubleshooting questions often involve 'show ip ospf interface' or 'show ip route' outputs. You might see a routing table showing two OSPF routes with equal cost, and the question asks why they have equal costs. Or you might see that a path with lower bandwidth is preferred, indicating that the cost was manually set incorrectly. In cloud exams, the scenario might involve a VPN failover not working because the OSPF metric on the primary circuit was higher than the backup. The question might ask: 'Which configuration change would make the primary circuit preferred?' The answer: lower the OSPF cost on the primary interface.

## Example scenario

A small company has two offices connected by two different Internet Service Providers (ISPs). The main office (Router A) is connected to the branch office (Router B) via a primary 100 Mbps fiber link and a backup 10 Mbps DSL link. Both links run OSPF to exchange routes. The network administrator wants all traffic to use the primary fiber link unless it fails.

Using the default OSPF cost formula with a 100 Mbps reference bandwidth, the fiber link (100 Mbps) gets a cost of 1, and the DSL link (10 Mbps) gets a cost of 10. OSPF will correctly choose the fiber link because its total path cost is lower. However, if the administrator later upgrades the fiber link to 1 Gbps, the cost remains 1 (since 100 Mbps / 1000 Mbps = 0.1, rounded to 1). Both links now have a cost of 1, and OSPF will load balance across them, even though the fiber link is much faster. This is not desired.

To solve this, the administrator can either change the reference bandwidth on both routers to 1 Gbps using the 'auto-cost reference-bandwidth 1000' command (making the 1 Gbps link cost 1 and the 10 Mbps link cost 100), or manually set the cost on the DSL link to a higher value like 100 using 'ip ospf cost 100'. Now, the fiber link has a lower cost and will be preferred. This scenario illustrates the importance of understanding the metric and how to configure it for optimal routing.

## How OSPF Metric Cost Works

In OSPF, the metric is referred to as cost and is the primary factor used to determine the best path to a destination network. Cost is an integer value assigned to each OSPF-enabled interface, and the total cost of a route is the sum of the costs of all outgoing interfaces along the path from the source to the destination. By default, Cisco IOS calculates the cost using the formula: reference-bandwidth / interface-bandwidth, where the reference bandwidth is 100 Mbps. This means a Fast Ethernet interface (100 Mbps) has a cost of 1, a 10 Mbps Ethernet interface has a cost of 10, and a T1 link (1.544 Mbps) has a cost of 64. A Serial interface at 128 Kbps would have a cost of 781 ({100,000 / 128 = 781.25}, rounded down).

This default behavior often leads to suboptimal routing in modern networks with higher-speed links. For example, a 1 Gbps interface has a cost of 0.1, which is not a valid integer in the OSPF cost field. To resolve this, engineers can manually set the cost on an interface with the "ip ospf cost" command, bypassing the automatic calculation entirely. Alternatively, the reference bandwidth can be changed globally using the "auto-cost reference-bandwidth" command. For instance, setting it to 10000 will make 10 Gbps interfaces cost 1, while a 1 Gbps interface costs 10. This adjustment is critical for networks with mixed link speeds, ensuring that OSPF prefers higher-bandwidth paths.

Cost values range from 1 to 65535. Paths with a lower total cost are preferred. If multiple paths to the same network have equal cost, OSPF will load balance across them (up to 4 or more, depending on the platform). The cost is also recalculated dynamically if the interface bandwidth changes, which can cause routing instability if not carefully managed. In exam scenarios, you must understand that cost is inversely proportional to bandwidth and is the only metric used by OSPF for path selection. Unlike other routing protocols that use hop count or delay, OSPF cost allows fine-grained control. For the CCNA or Network+ exams, you will often be asked to calculate the cost of a path given interface bandwidths, or to troubleshoot why a certain route is not being chosen-usually because a high-cost link is inadvertently preferred over a lower-cost one.

## OSPF Metric in Path Selection and Load Balancing

OSPF uses the shortest path first (SPF) algorithm, developed by Edsger Dijkstra, to build a loop-free topology of the network. Each router maintains a link-state database (LSDB) containing the state of all OSPF-enabled interfaces across the area. The metric (cost) of each link is advertised in the link-state advertisements (LSAs), specifically Type 1 Router LSAs and Type 2 Network LSAs. The SPF algorithm calculates the shortest path tree with itself as the root, summing the costs of all links to reach each destination. For example, if Router A has a path to network X with total cost 50 via Router B, and another path with cost 70 via Router C, the SPF algorithm selects the path with cost 50.

When there are multiple equal-cost paths to the same destination network, OSPF performs equal-cost multipath (ECMP) load balancing. The number of ECMP paths allowed is platform-dependent; Cisco routers default to 4, configurable up to 16 or 32 on some platforms. This is a powerful feature for increasing throughput without relying on higher-layer load balancing. However, note that OSPF does not consider load or delay-only cost. So, if you need to load balance across unequal-cost paths, you must either adjust costs manually or use other mechanisms like policy-based routing.

The path selection process is also influenced by LSA types. For external routes redistributed into OSPF, the metric includes an external cost (Type 1 or Type 2). Type 2 external routes add a fixed cost (default 20) to the internal path cost, while Type 1 adds the cumulative internal cost plus the redistributed metric. This distinction matters in exam questions about route preference, especially when comparing E1 and E2 routes. OSPF stub areas and totally stubby areas modify the path selection by preventing certain LSA types, which affects how costs are calculated for external destinations.

In the Security+ and AWS SAA exams, understanding OSPF metric helps when troubleshooting hybrid cloud connectivity. AWS Direct Connect and VPN attachments often use BGP, but OSPF is common in on-premises network designs that connect to AWS via virtual private gateways. The metric ensures that the shortest path through multiple VPN tunnels is preferred. For the Azure AZ-104 exam, similar concepts apply when using Azure VPN Gateways with OSPF. Knowing how to manipulate cost ensures effective traffic engineering in a multi-cloud environment.

## Manually Manipulating OSPF Metric for Traffic Engineering

Traffic engineering is the practice of influencing how packets flow through a network by adjusting routing metrics. In OSPF, the most direct way to engineer traffic is by setting the interface cost with the "ip ospf cost" command. For instance, if you have two links between two routers-one GigabitEthernet and one FastEthernet-by default the GigabitEthernet would have a cost of 1 and the FastEthernet a cost of 10. OSPF would prefer the GigabitEthernet. But if you want to force traffic over the FastEthernet (e.g., to save bandwidth on the faster link for critical applications), you can set the cost of the GigabitEthernet to 20 using "ip ospf cost 20". The OSPF SPF algorithm will then prefer the FastEthernet path (cost 10) over the GigabitEthernet (cost 20).

Another method is to adjust the reference bandwidth using "auto-cost reference-bandwidth" under router ospf configuration mode. Changing the reference from 100 Mbps to, say, 1000 Mbps will affect all interfaces on the router. This is useful to ensure that high-speed interfaces (like 10 Gbps) get a reasonable cost (10,000 / 10,000 = 1). However, be careful: if only one router in the area has a different reference bandwidth, the cost calculation becomes inconsistent, potentially causing asymmetric routing. It is recommended to configure the same reference bandwidth on all OSPF routers in the area.

you can influence the metric of redistributed routes. When redistributing from another protocol (e.g., EIGRP, static, or connected), you can set the OSPF metric using the "metric" parameter in the redistribute command. For example, "redistribute static subnets metric 200" assigns a cost of 200 to all redistributed static routes. For external routes, you can choose Type 1 (metric includes internal cost) or Type 2 (fixed metric) via the "metric-type" option. This allows you to prefer one external path over another.

In exam environments, you will see questions asking you to configure OSPF to prefer a specific link, often accompanied by show commands like "show ip route" or "show ip ospf interface". You must understand that manipulating cost is the primary tool for OSPF traffic engineering. Also, be aware that cost can be set on a per-interface basis, per-neighbor, or per-route. Incorrect cost settings can lead to routing loops or suboptimal paths, so always verify with "traceroute" or "show ip ospf database".

## OSPF Metric Scenarios in CCNA, Network+, and Cloud Exams

Exam questions on OSPF metric frequently appear in the CCNA (200-301), CompTIA Network+ (N10-008), AWS SAA (SAA-C03), Azure AZ-104, and Google ACE certifications. These questions test your understanding of how cost is calculated, how path selection works, and how to troubleshoot metric-related issues. A common scenario involves a router with multiple links to the same destination, and you must determine which path OSPF will choose. For example, a router has three serial links: T1 (1.544 Mbps), E1 (2.048 Mbps), and T3 (45 Mbps). You must calculate the cost for each using the default reference of 100 Mbps. T1 cost = 100,000 / 1,544 = 64 (truncated), E1 cost = 100,000 / 2,048 = 48, T3 cost = 100,000 / 45,000 = 2. OSPF will choose the T3 link (cost 2). Then you may be asked what happens if you set the cost of the T3 link to 100 manually-the answer is OSPF will then prefer the E1 link (cost 48) or T1 (cost 64) depending on the lowest cost.

Another common exam question involves verifying OSPF routes. The "show ip route ospf" command displays OSPF-learned routes with their metric. For example, you might see "O 10.1.1.0/24 [110/65] via 192.168.1.1" where 110 is the administrative distance and 65 is the OSPF metric. The exam may ask why a certain route has a metric of 65 and you must determine which links contribute that cost. Also, questions about ECMP load balancing are common: if you see two equal-cost paths in the routing table, OSPF will load balance; if you change the cost of one, only the lower-cost path remains.

In cloud exams (AWS SAA, AZ-104, Google ACE), OSPF metric becomes relevant when designing hybrid networks. For instance, in AWS, you might use Site-to-Site VPN with dynamic routing (BGP over generic routing encapsulation (GRE) or OSPF). The metric determines which VPN tunnel is primary. In Azure, you can configure ExpressRoute with OSPF to prefer one circuit over another by adjusting the MED (Multi-Exit Discriminator) or OSPF cost. The exam will ask you to design a high-availability connection where a failover occurs if the primary link's metric increases beyond a threshold. Understanding OSPF metric manipulation is key to ensuring planned failover scenarios.

Finally, the exam may present a troubleshooting scenario where a network loop occurs due to incorrect OSPF cost configuration. For example, if two routers both think they have the lowest-cost path to a network because of a misapplied cost command, the adjacency might still form but routing can become asymmetric. The symptom might be packet loss or high latency. The solution is to check the cost on each interface with "show ip ospf interface" and adjust them to create a consistent shortest path tree.

## Common mistakes

- **Mistake:** Believing OSPF uses hop count as its primary metric.
  - Why it is wrong: OSPF uses cost, which is usually derived from bandwidth, not the number of hops. Hop count is used by RIP, not OSPF.
  - Fix: Remember that OSPF cares about the quality (speed) of each link, not just the number of routers to pass through.
- **Mistake:** Thinking that a higher OSPF metric means a better path.
  - Why it is wrong: In OSPF, a lower cost is better. The algorithm picks the path with the smallest total cost.
  - Fix: Always think 'lower is better' for OSPF cost. It is like a lower price or shorter travel time.
- **Mistake:** Using the default reference bandwidth (100 Mbps) in a network with gigabit links and expecting accurate differentiation.
  - Why it is wrong: With 100 Mbps reference, all links from 100 Mbps to 10 Gbps get a cost of 1, making them indistinguishable for path selection.
  - Fix: Adjust the reference bandwidth to match the highest-speed link in the network, such as 1 Gbps or 10 Gbps.
- **Mistake:** Forgetting that OSPF cost is assigned to the outgoing interface of each router along the path.
  - Why it is wrong: Some learners think the cost is based on the incoming interface or the entire router. The cost is only added when the router forwards traffic out an interface.
  - Fix: When calculating path cost, only add the cost of the interface that a router uses to send packets to the next hop.
- **Mistake:** Confusing OSPF metric with administrative distance.
  - Why it is wrong: Administrative distance is used to choose between different routing protocols (e.g., OSPF vs EIGRP). OSPF metric is used only within OSPF to choose between multiple routes learned by OSPF.
  - Fix: Administrative distance decides which routing protocol is trusted; the OSPF metric decides which OSPF route is best.

## Exam trap

{"trap":"The exam presents a scenario where a network has a mix of 100 Mbps and 1 Gbps links, and asks why OSPF is load balancing equally across them even though the 1 Gbps link is faster. The trap is that the learner does not realize the default reference bandwidth causes both to have cost 1.","why_learners_choose_it":"Learners may think OSPF automatically prefers higher bandwidth without factoring in the reference bandwidth calculation.","how_to_avoid_it":"Always remember the default cost formula: Cost = 100 Mbps / link bandwidth. For links >= 100 Mbps, the cost is 1 unless the reference bandwidth is changed. Also, know that the 'auto-cost reference-bandwidth' command can fix this."}

## Commonly confused with

- **OSPF metric vs Administrative Distance (AD):** OSPF metric determines the best path within OSPF, while administrative distance determines which routing protocol is more believable when multiple protocols know about the same route. AD is a trust rating, not a metric. (Example: If OSPF says a route costs 10 and EIGRP says it costs 20, the router uses AD to decide which protocol to trust (usually OSPF has AD 110, EIGRP has AD 90, so EIGRP wins). The OSPF metric is only used if the router chooses OSPF.)
- **OSPF metric vs Hop count (RIP metric):** RIP uses hop count, which counts the number of routers between source and destination. OSPF uses cost based on bandwidth, which often results in a different path choice. (Example: A network has a path with 2 fast routers and another with 1 slow router. RIP would choose the 1-hop path, while OSPF would likely choose the 2-hop path if the fast links have lower cost.)
- **OSPF metric vs OSPF area:** An OSPF area is a logical grouping of routers that limits the propagation of link-state information. The metric is a value used inside an area (and between areas) to choose paths, but areas do not affect metric calculation directly. (Example: All routers in area 0 share the same link-state database, and metrics are calculated normally. An area boundary router summarizes routes but still uses metric to choose the best path.)
- **OSPF metric vs EIGRP metric (composite metric):** EIGRP uses a composite metric based on bandwidth, delay, load, reliability, and MTU. OSPF uses only a simple cost based on bandwidth (or manually set). EIGRP is more complex. (Example: For a link with 1 Gbps bandwidth and 10 ms delay, EIGRP calculates a composite metric, while OSPF simply assigns cost = 1 (if reference is 100 Mbps).)

## Step-by-step breakdown

1. **Interface Bandwidth Determination** — When OSPF is enabled on an interface, the router reads the configured bandwidth value of the interface (not the actual speed). On Cisco devices, this is usually set automatically based on the interface type, but it can be manually changed with the 'bandwidth' command.
2. **Cost Calculation using Formula** — The router calculates the cost using Cost = Reference Bandwidth (default 100 Mbps) / Interface Bandwidth (in Mbps). The result is rounded down to the nearest integer if needed, but the minimum cost is 1.
3. **Cost Storage in the Link State Advertisement (LSA)** — The computed cost is stored in the LSA for the link. This LSA is flooded to all OSPF neighbors in the same area. The LSA contains the router's ID and the cost for each directly connected link.
4. **Flooding LSAs to All Routers** — Each router sends its LSAs to all neighboring routers, which in turn forward them to their neighbors, until every router in the area has a complete copy of the link-state database (LSDB). The LSDB contains all LSAs from all routers.
5. **Building the Topology Map** — Each router uses the LSDB to build a complete graph of the network, with routers as nodes and links as edges. Each edge (link) has an associated cost value.
6. **Running the Dijkstra SPF Algorithm** — The router runs Dijkstra's Shortest Path First algorithm on the graph to compute the shortest (lowest total cost) path from itself to every other node (network). The algorithm iteratively selects the node with the lowest cumulative cost from the source and updates the distances.
7. **Populating the Routing Table** — The best paths (lowest cost) are installed in the routing table. If multiple paths have the same cost, they are all installed, and the router can load balance (ECMP). The routing table entry includes the destination network, next-hop address, and outgoing interface.
8. **Recalculation on Topology Change** — If a link goes down or a new link appears, the affected router sends updated LSAs. All routers in the area receive the update, run the SPF algorithm again, and update their routing tables. This ensures that the metric always reflects the current network state.

## Practical mini-lesson

In a real-world production network, the OSPF metric is not just a static number; it is a dynamic tool that network engineers use to control traffic flow. The first thing to understand is that the default cost formula uses bandwidth, but bandwidth is only an accurate reflection of link speed if the interface bandwidth is correctly configured. Many engineers forget to set the bandwidth on serial links, which default to 1.544 Mbps (T1). If the actual link is a 10 Mbps E1, the cost will be wrong. Always verify with 'show ip ospf interface' to see the actual cost being used.

A common best practice is to adjust the reference bandwidth to match the fastest links in the network. For a network with 1 Gbps and 10 Gbps links, set the reference bandwidth to 10000 (10 Gbps) using 'auto-cost reference-bandwidth 10000'. This ensures that a 1 Gbps link gets cost = 10, a 10 Gbps link gets cost = 1, and a 100 Mbps link gets cost = 100. This granularity allows OSPF to make precise path decisions. However, this command must be configured on every router in the OSPF domain for consistency; otherwise, different routers will compute different costs for the same link.

Manually setting the cost is another common practice. When you want to force traffic away from a particular link, increase its cost. For example, to make a backup link less preferred, set its cost to a very high number like 1000. Conversely, to force traffic onto a link, set its cost to 1. Manual cost overrides are typically done in stub networks or for policy-based routing. But be careful: manual overrides can cause routing loops if done inconsistently. Always document any manual cost changes.

What can go wrong? One common issue is that OSPF can choose a high-bandwidth path that is actually congested, because the metric does not reflect real-time utilization. OSPF is a static metric protocol; it does not adapt to congestion. If you need dynamic path selection based on load, you would use something like MPLS TE or a different protocol. Another issue is that the OSPF metric is only relevant within the same area (intra-area). Inter-area routes use a summary cost that may not represent the exact path. Understanding these limitations is key to avoiding network problems.

Finally, when troubleshooting, use 'show ip ospf interface' to check the cost on a specific interface. Use 'show ip route ospf' to see which routes OSPF has installed and their metrics. Use 'debug ip ospf spf' to see when the SPF algorithm runs and why. If a route is missing, check if the cost makes sense. If a route is present but traffic is going elsewhere, verify that the metric is truly lower. In many cases, a simple manual cost adjustment can solve traffic engineering problems without reconfiguring the entire network.

## Commands

```
Router(config-if)# ip ospf cost 10
```
Manually sets the OSPF cost of the interface to 10, overriding the default bandwidth-based cost calculation. Use this to engineer traffic over a specific interface.

*Exam note: Tests your ability to manipulate OSPF path selection. Often asked in CCNA where you need to force traffic over a slower link for cost reasons.*

```
Router(config-router)# auto-cost reference-bandwidth 10000
```
Changes the reference bandwidth from the default 100 Mbps to 10000 Mbps (10 Gbps). This ensures that high-speed interfaces like 10 Gbps get a cost of 1. Use in networks with links faster than 100 Mbps.

*Exam note: Common in Network+ and CCNA exams. Be aware that this command must be consistent across all routers in the area to avoid routing issues.*

```
Router# show ip route ospf
```
Displays only OSPF-learned routes in the routing table, including the metric (cost) and next-hop. Use to verify which OSPF routes are being used.

*Exam note: Heavily used in simulations and multiple-choice questions to identify the metric of a specific route. Expect to see output like [110/20] where 110 is AD and 20 is cost.*

```
Router# show ip ospf interface serial 0/0/0
```
Shows detailed OSPF information for a specific interface, including the OSPF cost, state, and neighbors. Useful for verifying cost settings.

*Exam note: Exams ask you to determine why a link is not being used – check the cost versus other interfaces. The cost field is clearly displayed.*

```
Router(config)# router ospf 1
Router(config-router)# redistribute static subnets metric 50 metric-type 1
```
Redistributes static routes into OSPF with a metric of 50, and sets the external metric type to E1 (Type 1). This adds the internal path cost to the redistributed route, allowing for more accurate path selection.

*Exam note: Differentiates between Type 1 and Type 2 external routes. In exams, understand that E1 routes are additive with internal cost, E2 routes are not.*

```
Router(config-if)# bandwidth 100000
```
Sets the interface bandwidth to 100,000 Kbps (100 Mbps). This indirectly changes the OSPF cost when using default cost calculation, as cost = ref-bw / bandwidth. Use when you want to adjust cost without explicitly setting it.

*Exam note: Changing bandwidth affects OSPF cost and other protocols. Exam questions may test that OSPF cost is derived from bandwidth if no explicit cost is set.*

## Troubleshooting clues

- **OSPF prefers a slower link over a faster link** — symptom: Traffic goes through a 1.544 Mbps T1 link instead of a 100 Mbps FastEthernet link, causing high latency.. The T1 link might have a lower OSPF cost (e.g., because the FastEthernet cost was manually set too high, or the T1 link has a misconfigured bandwidth). Default cost calculation would give T1 cost 64 and FastEthernet cost 1, but if someone set ip ospf cost 50 on FastEthernet, T1 becomes cheaper (64 vs 50). (Exam clue: Exam scenarios ask you to identify why a slower link is preferred – check the cost on each interface with show ip ospf interface.)
- **OSPF route has unexpectedly high metric** — symptom: A directly connected network shows a route with metric 100 even though the link is GigabitEthernet.. The interface bandwidth might have been set to a low value (e.g., 1000 Kbps) which increases the cost. Alternatively, the reference bandwidth might be misconfigured. For example, if auto-cost reference-bandwidth is set to 100000, a GigabitEthernet (1,000,000 Kbps) gets cost 100. (Exam clue: Tests understanding that changing bandwidth or reference bandwidth affects the metric, even if no explicit cost is set.)
- **Equal-cost paths not being load balanced** — symptom: Only one path appears in the routing table to a destination, even though there are two links with same cost.. OSPF ECMP load balancing is enabled by default, but the maximum number of paths may be set to 1 or the paths may not truly be equal. Verify with show ip route and check if both routes have exactly the same metric. Also check if the platform supports ECMP (Cisco defaults to 4 paths). (Exam clue: In Network+ or CCNA, you might need to configure maximum-paths or verify that the cost is identical.)
- **External routes (E2) not chosen over internal routes** — symptom: A redistributed route with metric 20 is not appearing in the routing table, but there is an inter-area route to same destination with higher metric.. OSPF prefers intra-area routes over inter-area routes, and inter-area over external routes, regardless of metric. So if there is any OSPF internal route (even with high cost) to the destination, external routes are not installed. Check the route type in show ip route. (Exam clue: Understand the route preference hierarchy: O (intra-area) > O IA (inter-area) > N1/N2 (NSSA) > E1/E2 (external). Metric only compares within the same type.)
- **OSPF adjacency fails due to mismatched cost** — symptom: Router shows OSPF neighbor state as DOWN or INIT, but interfaces are up/up.. While cost itself does not cause adjacency failure, a mismatched interface cost between neighbors does not break adjacency. However, if the MTU or network type mismatch exists (which is related to cost in some implementations), the adjacency may fail. Ensure both sides have consistent OSPF settings. (Exam clue: Know that cost mismatches do not prevent adjacency; they affect path selection only. Check for other mismatches like area ID, authentication, or network type.)
- **OSPF cost not updated after bandwidth change** — symptom: After changing the bandwidth on an interface, the OSPF metric remains the same.. OSPF does not recalculate the cost dynamically if the cost was set manually with ip ospf cost. Manual cost overrides bandwidth-based calculations. If you want cost to change with bandwidth, remove the explicit cost command. (Exam clue: In exam, be sure to understand the precedence: manual cost > bandwidth-based cost. Show commands help identify if cost is manually set.)
- **Suboptimal path due to incorrect reference bandwidth on some routers** — symptom: All routers in the area have different costs for the same link, causing routing loops or asymmetric paths.. Each router calculates cost based on its own reference bandwidth and interface bandwidth. If one router uses reference of 1000 and another uses 100, a 1 Gbps link will have different costs (1 vs 10). The SPF tree becomes inconsistent. (Exam clue: Exams test the concept of consistent reference bandwidth across the OSPF domain. Use the auto-cost reference-bandwidth command with same value on all routers.)

## Memory tip

Think OSPF Cost = 'Lower is Faster', a low cost means a fast road, a high cost means a slow road.

## FAQ

**What is the default OSPF cost for a 1 Gbps link?**

With the default reference bandwidth of 100 Mbps, the cost is 100 / 1000 which is 0.1, rounded down to 1. So a 1 Gbps link gets a cost of 1, same as a 100 Mbps link.

**Can I manually set the OSPF cost on an interface?**

Yes. On Cisco devices, use the 'ip ospf cost [value]' interface configuration command. The value can range from 1 to 65535. This overrides the auto-calculated cost.

**Why does OSPF use cost instead of hop count?**

Hop count ignores link speed. Cost based on bandwidth allows OSPF to choose faster paths even if they have more hops. This often results in better performance.

**How does OSPF handle equal-cost paths?**

If multiple paths have exactly the same total metric, OSPF will install up to four (or more with the maximum-paths command) equal-cost paths in the routing table and load balance traffic across them.

**What happens if I change the reference bandwidth on only one router?**

Inconsistent reference bandwidth across routers can cause mismatched cost calculations, leading to routing loops or suboptimal path selection. Always change it on all routers in the OSPF domain.

**Does OSPF metric consider link reliability or load?**

No. OSPF metric is based solely on the configured bandwidth of the interface (or a manually set cost). It does not automatically adjust for actual utilization or link errors.

**What is the maximum OSPF cost for a single link?**

The OSPF metric field in the LSA is 16 bits, so the maximum cost for a link is 65535. The total path cost is also limited to 16 bits (max 65535) in the SPF algorithm.

**Is OSPF metric used in OSPFv3 (IPv6)?**

Yes. OSPFv3 uses the same metric concept (cost based on bandwidth) as OSPFv2, though the LSA format is different. The 'ipv6 ospf cost' command is used to set it manually.

## Summary

The OSPF metric is the fundamental tool that the OSPF routing protocol uses to determine the best path through a network. It is a cost value, usually derived from the bandwidth of each link, with lower costs indicating faster or more desirable paths. OSPF's Shortest Path First algorithm sums these costs along each possible route and selects the path with the lowest total. This approach is smarter than older protocols that rely on hop count, because it takes into account the actual speed of network links.

For certification exams, especially CCNA and Network+, you must know the default cost formula (Cost = 100 Mbps / Interface Bandwidth), be able to calculate costs for different link speeds, and understand how manual cost overrides work. Common mistakes include confusing metric with administrative distance, thinking higher metric is better, and forgetting to adjust the reference bandwidth in modern high-speed networks. The metric also plays a role in cloud certification exams where OSPF is used in VPN or ExpressRoute failover scenarios.

In practice, the OSPF metric gives network engineers precise control over traffic flow. By adjusting reference bandwidth or manually setting interface costs, an engineer can influence which paths are preferred, enabling load balancing, failover, and traffic engineering. Misconfiguration of the metric can lead to poor network performance or routing loops, so it is important to verify settings using 'show ip ospf interface' and 'show ip route ospf'. Understanding the OSPF metric is not just an exam requirement; it is a practical skill for anyone managing routed networks.

---

Practice questions and the full interactive page: https://courseiva.com/glossary/ospf-metric
