# Cost

OSPF's metric is called **cost**.

It is automatically calculated based on the bandwidth (speed) of the interface.

It is calculated by dividing a **reference bandwidth** value by the interface's bandwidth.

The default reference bandwidth is 100 mbps.

* **Reference**: 100 mbps / **Interface**: 10 mbps = cost of **10**.
* **Reference**: 100 mbps / **Interface**: 100 mbps = cost of **1**.
* **Reference**: 100 mbps / **Interface**: 1000 mbps = cost of **1??**.
* **Reference**: 100 mbps / **Interface**: 10000 mbps = cost of **1??**.

All values less than 1 will be converted to 1.

Therefore FastEthernet, Gigabit Ethernet, 10Gig Ethernet, etc, are equal and all have a cost of 1 by default.

<figure><img src="/files/1NV4gQIUOqNSQY5d47YI" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/FnjYLOmoeVACz2SAvRNJ" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/ZGYF6yhBh9fgrz7fJY3I" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/0P0fiHVOfkAYJy97irEy" alt=""><figcaption></figcaption></figure>

You can (and should!) change the reference bandwidth with this command.

```
R1(config-router)# auto-cost reference-bandwidth <megabits-per-seconds>
```

<figure><img src="/files/DW4iZrAZX6uBWYHQZ4aC" alt=""><figcaption></figcaption></figure>

The command is entered in megabits per seconds (defualt is 100).

* 100000 / 100 = cost of 1000 for FastEthernet.
* 100000 / 1000 = cost of 100 for GigEtherner.

You should configure a reference bandwidth greater thant the fastest links in your network (to allow for future upgrades).

You should configure the same references bandwidth on all OSPF routers in the network.

The OSPF cost to a destination is the total cost of the 'outgoing/exit interfaces'

For example, R1's cost to reach 192.168.4.0/24 is:

* 100 (R1 G0/0) + 100 (R2 G1/0) + 100 (R4 G1/0) = 300

<figure><img src="/files/DaXLShm32REnxBummhiR" alt=""><figcaption></figcaption></figure>

Loopback interfaces have a cost of 1.

What is R1's const to reach 2.2.2.2 (R2's loopback0 interface)?

* 100 (R1 G1/0) + 1 (R2 L0) = 101

<figure><img src="/files/uENEKWfbXYCUGwWPVAU1" alt=""><figcaption></figcaption></figure>

One more option to change the OSPF cost of an interface is to change the bandwidth of the interface with the ***bandwidth*** command.

The formula to calculate OSPF cost is **reference bandwidth** / **interface bandwidth**.

Although the bandwidth matches the interface speed by default, changing the interface bandwidth **doesn't actually change the speed at which the interface operates**.

The bandwidth is just a value that is used to calculate OSPF cost, EIGRP metric, etc.

To change the speed at which the interface operates, use the ***speed*** command.

Because the bandwidth value is used in other calculations, it is not recommended to change this value to alter the interface's OSPF cost.

It is recommended that you change the reference bandwidth, and then use the ***ip ospf cost*** command to change the cost of individual interfaces if you want.

<figure><img src="/files/OYZ4e4CvbFsnBPEe6zSN" alt=""><figcaption></figcaption></figure>

## Summary

Three ways to modify the OSPF cost:

1. Change the **reference bandwidth**:

```
R1(config-router)# auto-cost reference-bandwidth <megabits-per-seconds>
```

2. Manual configuration

```
R1(config-if)# ip ospf cost <cost>
```

3. Change the **interface bandwidth**

```
R1(config-ig)# bandwidth <kilobits-per-seconds>
```

<figure><img src="/files/6ZBLHAa058lkympeIkSP" alt=""><figcaption></figcaption></figure>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://davidjosearaujo.gitbook.io/online-courses/ccna-200-301/dynamic-routing/ospf/cost.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
