The quick download:
Don’t treat OSPF and BGP as interchangeable. Each is engineered for a specific scope and role.
-
OSPF is a link-state protocol designed for fast convergence inside a single autonomous system, using hierarchical areas to scale to several hundred routers.
-
BGP is the de facto standard for inter-domain routing across the Internet, using path attributes instead of simple cost metrics to give operators granular control over inter-domain routing decisions.
-
Both protocols can get complex quickly: OSPF through its multiple area and LSA types, BGP through its extensive attribute manipulation and best-path selection logic.
-
Start with clear requirements around network scope, convergence speed, and administrative control before choosing a protocol. The wrong fit creates more problems than it solves.
BGP vs OSPF
Routing protocols are used to automatically and dynamically exchange routing information between routers. There are several routing protocols to choose from, each with its own pros and cons, as each routing protocol is designed to be well-suited to a particular network implementation scenario. Two of the most popular routing protocols used today are Open Shortest Path First (OSPF) and Border Gateway Protocol (BGP). These are very different in their design, as we shall see. We’ll start with a summary of the differences and then explain each protocol in more depth.
OSPF
OSPF is an interior gateway protocol (IGP) that routes packets within a single Autonomous System (AS). Unlike other IGPs, OSPF is a link-state routing protocol. In other words, it relies on link-state information to calculate route paths and make routing decisions.
After the protocol starts, each router running OSPF sends link-state advertisements (LSAs) throughout the AS or area containing information about its connected interfaces and routing metrics. When there is a change to any router, it is propagated to all routers in the area. Such an update triggers a rerun of the shortest-path-first algorithm.
OSPF splits each AS into smaller sections called areas. All the routers in the same area have identical LSA databases. They have also summarized information about the other areas. There are multiple types of OSPF areas, which will be described later in this article.
BGP
BGP is a routing protocol primarily used for inter-domain routing and is considered an External Gateway Protocol (EGP). However, BGP can also be used to advertise networks within an AS and, when configured to do so, can function similarly to IGPs.
BGP is used to exchange routing information among routers in the same AS or different ASs. An AS is a set of routers under a single administrative authority. An AS path is the route to a destination. It is also a list of ASs that the route passes through to reach a particular router. Each route has additional information attached that comes in the form of path attributes. The path attributes are used in routing policies to influence how the router routes the traffic.
Summary of differences between OSPF and BGP
Below is a summary of some of the differences between OSPF and BGP.
| OSPF | BGP | |
| Routing domain | Intra-domain | Primarily Inter-domain but can also be used as intra-domain |
| Maximum size of the network | Can be deployed in mid-sized to large networks with up to several hundred routers | Scalable to the worldwide Internet |
| Implementation | Easy for basic configuration | Easy to moderately difficult for basic configuration |
| Network topology | Hierarchical | Mesh, but can be modified to star using a route reflector |
| Convergence | Fast | Slow |
| Resource requirements | Memory- and CPU-intensive | Directly proportional to the size of the routing table |
| Metric | Based on bandwidth/cost | Based on BGP attributes |
Table 1: Summary of OSPF vs. BGP.
Differences between OSPF and BGP
There are several differences between OSPF and BGP. To start with, OSPF is an interior gateway protocol. Therefore, it is confined to a single domain for routing (intra-domain). On the other hand, BGP is primarily designed to route between routing domains (inter-domain).
OSPF can be successfully deployed in networks with several hundred routers in a single flat area. However, this is directly related to the resources available on the routers (see below for the resource requirements). Conversely, the only routing protocol that runs on the Internet exclusively is BGP.
The basic configuration of OSPF (say, a single area with no fancy features enabled) is relatively easy. Even the most basic BGP configuration requires more effort than OSPF’s basic configuration (and some advanced routing knowledge). While both OSPF and BGP can get very complex, BGP is far more difficult to use due to the numerous features available, which make it suitable for many situations and corner cases. For example, OSPF primarily uses a metric to determine the best route. BGP, on the other hand, uses a set of attributes that can be adjusted with fine granularity to modify routing behavior in multiple ways.
OSPF must be deployed hierarchically (we will discuss this in the next section), whereas BGP does not require any hierarchy to scale.
In terms of convergence, OSPF reacts faster to network changes than BGP. This makes sense, given that BGP is designed for vast networks where changes happen more often statistically. You would not want routers on large networks to be constantly recalculating routes.
As for resource requirements, OSPF’s constant recalculation makes it CPU- and memory-intensive. In contrast, BGP does not respond that quickly and becomes CPU- and memory-intensive as the routing table grows. Therefore, routers that hold the Internet routing table require powerful CPUs and a lot of memory.
Regarding the metric used to calculate the best route, OSPF uses a cost derived from interface bandwidth and the costs advertised by other routers when the LSA is sent. BGP can use any BGP attributes to select the best route.
The inner workings of OSPF and BGP
This section describes the two protocols in more detail. We will focus on the most common options we will see configured in the next section of the article.
OSPF
As mentioned in the first section, OSPF is a link-state routing protocol. OSPF routers exchange link-state advertisements that describe the networks they know about. From these advertisements, each OSPF router builds a full topology of the network in its memory. Before doing this, though, they need to establish an adjacency with neighboring OSPF routers. Before establishing an adjacency, the two routers must become neighbors. The routers find each other using Hello packets.
The following information from the Hello packets sent by the two routers must match:
- They should be in the same area.
- The router ID must be unique.
- The subnet must be the same.
- The Hello and dead timer must be the same.
- The stub flag must match.
- The authentication must match.
It’s important to know that not all neighbor routers become adjacent. Let’s consider the scenario in Figure 1 (a broadcast or a non-broadcast multi-access network).

The OSPF Hello protocol will elect a designated router (DR) for the network in this particular example. For redundancy purposes, a backup designated router (BDR) will be elected. Every other router from the segment will become a DROther. This means that the DROther will become adjacent only to the DR and BDR, and every DROther router will receive the LSA from the DR (or the BDR if the DR fails).
The purpose of this mechanism is to reduce the amount of routing information traffic exchanged. There are two rules to elect the DR and BDR:
- Priority: Highest priority is preferred.
- Router ID: Highest router ID is preferred.
The router ID is derived using the following options:
- Manually set.
- The highest IP address from a loopback interface.
- The highest IP address from an up physical interface.
Should every OSPF configuration be left at default and all the routers be configured at exactly the exact moment, in the above case, R3 will become the DR, R2 the BDR, and R1 the DROther (Figure 2).

Above, the DROther sends its updates to the multicast IP address 224.0.0.6, which only the DR and BDR listen to. The DR sends the update to 224.0.0.5, which all routers in the segment listen to.
It was mentioned that OSPF was designed to be hierarchical and scalable, achieved through OSPF areas. Based on the type of LSAs that can be present in an area, these are the OSPF areas:
| Area Types | LSA 1 | LSA 2 | LSA 3 | LSA 4 | LSA 5 | LSA 7 |
| Backbone Area | Yes | Yes | Yes | Yes | Yes | No |
| Non-backbone Area | Yes | Yes | Yes | Yes | Yes | No |
| Stub Area | Yes | Yes | Yes | No | No | No |
| Totally Stubby Area | Yes | Yes | No | No | No | No |
| Not-So-Stubby Area | Yes | Yes | Yes | No | No | Yes |
Table 2: OSPF areas.
It is worthwhile to discuss what each LSA type is:
- LSA Type 1 – Router LSA: Generated by every router and describes the router links.
- LSA Type 2 – Network LSA: Generated by the DR and describes the routers connected to the segment.
- LSA Type 3 – Network Summary LSA: Generated by the Area Border Router and sent to another area to represent the destinations outside that area.
- LSA Type 4 – ASBR Summary: Used to describe the router that advertises external routes.
- LSA Type 5 – AS External LSA: Represents the routes external to the AS.
- LSA Type 7 – NSSA External: Represents the external routes from an NSSA area that will be converted to Type 5 LSA.
Now let’s discuss the router types in OSPF, as shown in Figure 3.

In this particular case, area 0 is the backbone area, the rest of the areas are non-backbone areas, and these are the roles of the routers:
- R1 and R2: Internal routers because all their interfaces are in the same area.
- R3 and R4: Area Border Routers because their interfaces are in two different areas. They are also called backbone routers because they have at least one interface in Area 0.
- R5: Autonomous System Border Router, which redistributes external routes (BGP) in OSPF.
BGP
As already mentioned, BGP is used to connect ASes or to advertise network reachability information inside an AS.
When BGP is configured between routers in the same AS, it is called Internal BGP. When it is configured between routers in different ASes, it is called External BGP (Figure 4).

In this example, the BGP session between R1 and R2 is internal, and the BGP session between R2 and R3 is external. The network reachability information is sent via BGP Update messages, enabling the advertisement and withdrawal of routes.
One of the most critical fields in the Update message is the “Path Attributes,” which define what attributes are attached to the routes. There are four categories of BGP attributes:
- Well-Known Mandatory: These are recognized by all BGP speakers and must be present in all Update messages.
- Well-Known Discretionary: All BGP speakers recognize these messages, but they may optionally appear in Update messages.
- Optional Transitive: These may or may not be recognized by BGP speakers, but even so, they are passed to other BGP peers.
- Optional Non-Transitive: The BGP speakers might recognize these messages but not pass them to other BGP peers.
While OSPF uses cost as a metric to determine the best path, BGP uses BGP attributes to determine the best path. Because it is not uncommon to have multiple paths to the same destination, BGP has a best-path selection algorithm to eventually choose the best path (or paths, if BGP multipath is configured).
Detailed information about the exact steps for the algorithm are described here and here.
One thing to remember is that a route will be considered a candidate for the best path only if the next hop on that route is reachable.
Consider Figure 5. By default, if no additional actions are taken on R2, R1 will not accept the 10.10.10.0/24 route because, in the BGP Update message, the next hop for the route is R3, and R1 does not know how to reach it.

There are multiple ways to solve the problem above, and they are listed below:
- R2 can set itself as the next-hop-self for the BGP update sent to R1, so R1 now has the next-hop IP address within its routing table.
- R2 can advertise the subnet between R2 and R3 in the IGP of AS 1. This however, is less desirable, since inter AS communication should be restricted only to BGP, otherwise unpredictable routing may occur. It is best practice to keep IGPs operating within the boundaries of their ASes.
Configuration
This section shows how to configure basic OSPF and BGP on Cisco routers.
OSPF
For OSPF, we will use the following diagram of a multi-area OSPF network. In this scenario, R3 is the ABR because it has interfaces in both Area 0 and Area 1. Area 1 is a non-backbone area (not a stub, stubby, or NSSA).

Following interface configuration, this is what is required on R1 to be configured as an internal backbone router (the same configuration is done for R2 with the difference of IP addressing).
router ospf 1
network 1.1.1.1 0.0.0.0 area 0
network 10.10.10.1 0.0.0.0 area 0The configuration is similar for R4, except that the interfaces are added in Area 1.
R3 has a different configuration. Observe how interfaces are part of different areas.
router ospf 1
network 1.1.1.3 0.0.0.0 area 0
network 10.10.10.3 0.0.0.0 area 0
network 20.20.20.3 0.0.0.0 area 1Because all three routers in Area 0 were configured simultaneously and none of the OSPF parameters were changed, R3 became the DR, R2 became the BDR, and R1 became DROther. As mentioned before, the router ID of R3 was the highest because it has the highest loopback IP address out of the three routers in Area 0.
R1#show ip ospf neighbor Ethernet0/0
Neighbor ID Pri State Dead Time Address Interface
1.1.1.2 1 FULL/BDR 00:00:32 10.10.10.2 Ethernet0/0
1.1.1.3 1 FULL/DR 00:00:39 10.10.10.3 Ethernet0/0
R1#If you checked on R3, R1 would be in the state of DROther.
R3#show ip ospf neighbor Ethernet0/0
Neighbor ID Pri State Dead Time Address Interface
1.1.1.1 1 FULL/DROTHER 00:00:35 10.10.10.1 Ethernet0/0
1.1.1.2 1 FULL/BDR 00:00:31 10.10.10.2 Ethernet0/0
R3#Checking the routing table of R1, you would see routes from the same area (Area 0) and Area 1 (with the code of IA).
1.0.0.0/32 is subnetted, 4 subnets
O 1.1.1.2 [110/11] via 10.10.10.2, 00:06:55, Ethernet0/0
O 1.1.1.3 [110/11] via 10.10.10.3, 00:06:55, Ethernet0/0
O IA 1.1.1.4 [110/21] via 10.10.10.3, 00:06:55, Ethernet0/0
20.0.0.0/24 is subnetted, 1 subnets
O IA 20.20.20.0 [110/20] via 10.10.10.3, 00:06:55, Ethernet0/0This would be a basic configuration of a multi-area OSPF network. This kind of deployment will suffice for most networks.
BGP
For BGP, we will use the setup in Figure 7.

R1 and R2 are in AS1 (which means they will have an internal BGP between them), and R3 is in AS 2, so there will be an external BGP session between R2 and R3. R3 advertises the route for 1.1.1.1/32.
The configuration required for R1 is the one below.
router bgp 1
neighbor 10.10.10.2 remote-as 1The configuration for R2 is the one below.
router bgp 1
neighbor 10.10.10.1 remote-as 1
neighbor 20.20.20.3 remote-as 2And the configuration for R3. There is an additional command required to advertise the network 1.1.1.1/32, as noted below.
router bgp 2
network 1.1.1.1 mask 255.255.255.255
neighbor 20.20.20.2 remote-as 1At this point, R2 should have in its routing table the network 1.1.1.1/32, but R1 will not have it because the next hop of the route (20.20.20.3) is not reachable by R1.
R1#show ip route bgp
Gateway of last resort is not set
R1#sh ip bgp 1.1.1.1
BGP routing table entry for 1.1.1.1/32, version 0
Paths: (1 available, no best path)
Not advertised to any peer
Refresh Epoch 1
2
20.20.20.3 (inaccessible) from 10.10.10.2 (10.10.10.2)
Origin IGP, metric 0, localpref 100, valid, internal
rx pathid: 0, tx pathid: 0
R1#To solve this, we can configure R2 to set itself as the next-hop for the routes it advertises to R1.
router bgp 1
neighbor 10.10.10.1 remote-as 1
neighbor 10.10.10.1 next-hop-self
neighbor 20.20.20.3 remote-as 2This will allow R1 to install the route in the routing table.
Gateway of last resort is not set
1.0.0.0/32 is subnetted, 1 subnets
B 1.1.1.1 [200/0] via 10.10.10.2, 00:00:25
R1#At first glance, the BGP configuration is simple, but it is as basic as it gets. In reality, you would need to play around with BGP attribute manipulation and configure additional features. Some of the attributes that can be manipulated to affect BGP routing behavior include Local Preference, AS_PATH length, and MED to name a few. The BGP configuration can get very complex, and vendors constantly add new complex features to support more and more use cases.
Conclusion
The following are lists that summarize the pros and cons of each routing protocol. Note that some of the cons may not actually be considered cons in certain situations, so these should be taken only as guidelines.
OSPF
- Pros
- Fast convergence
- Open standard
- Scalable due to hierarchical area implementation
- Cons
- Uses large amounts of system resources (CPU, memory) to run algorithm and maintain full network topology information
- Multiple area types and link state advertisement types can become extensively complex
BGP
- Pros
- Extremely scalable
- Low resource usage even for large BGP tables
- Extremely granular routing behavior adjustments
- Cons
- Slow to converge
- Complexity can increase if many BGP attributes are tweaked
BGP and OSPF are complex protocols. Their configuration can be very difficult at times, and it is critical to understand how the protocols work and what their core components are. Failing to do so would not only prevent you from having the right configuration but also put you at risk of being unable to properly troubleshoot issues with these protocols.
It is also worth checking the latest vendor documentation for features and their configuration, as each feature’s defaults may change from release to release.
See your network infrastructure clearly with LogicMonitor, from routing protocols to application performance.
LogicMonitor delivers user-to-code visibility across your network, helping your team act on routing issues before they reach users.
FAQs
Can OSPF and BGP run on the same router?
Yes. It’s common for routers to run both protocols simultaneously. OSPF handles internal routing within the autonomous system, while BGP manages external routing between autonomous systems. The router can redistribute routes between the two protocols when needed, though this requires careful configuration to avoid routing loops.
When should I use BGP instead of OSPF?
Use BGP when you need to exchange routing information between different autonomous systems, when you’re connecting to the Internet through multiple ISPs, or when you need granular control over routing policies using path attributes. OSPF is the better choice for routing within a single organization’s network.
Why is BGP convergence slower than OSPF?
BGP is designed for large-scale networks like the Internet, where constant route recalculation would create instability. It uses timers and dampening mechanisms to prevent rapid route flapping. OSPF’s faster convergence is appropriate for smaller, controlled environments where quick adaptation to topology changes is more important than stability at scale.
What happens if a BGP next hop is unreachable?
The route won’t be installed in the routing table and won’t be considered for the best-path selection. This is a common issue in iBGP configurations where the next hop defaults to the external peer’s address. Solutions include configuring next-hop-self on the iBGP peer or advertising the external subnet in the IGP.




