50% OFF on All Courses!

Popular:

Your cart is empty

Your cart is empty

BGP vs OSPF: When to Use Which Protocol (2026 Guide)

Use OSPF inside your own network for fast, automatic routing between your routers. Use BGP when connecting to the Internet, peering with another company, or running a large-scale data centre fabric. OSPF is an Interior Gateway Protocol (IGP). BGP is an Exterior Gateway Protocol (EGP). They solve different problems, and most serious networks run both at the same time.
BGP vs OSPF

TL;DR: Use OSPF inside your own network for fast, automatic routing between your routers. Use BGP when connecting to the Internet, peering with another company, or running a large-scale data centre fabric. OSPF is an Interior Gateway Protocol (IGP). BGP is an Exterior Gateway Protocol (EGP). They solve different problems, and most serious networks run both at the same time.

That’s the short answer. If you’re studying for a Cisco exam, designing an enterprise network, or just want to stop confusing these two in interviews, this guide walks you through every practical difference, with config snippets and decision rules you can apply today.

BGP vs OSPF at a Glance

Here’s the one-page comparison you came for.

AttributeOSPFBGP
TypeInterior Gateway Protocol (IGP)Exterior Gateway Protocol (EGP)
AlgorithmLink-state (Dijkstra SPF)Path-vector
ScopeInside one Autonomous System (AS)Between Autonomous Systems
MetricCost (based on bandwidth)Path attributes (AS_PATH, LOCAL_PREF, MED, etc.)
TransportIP protocol 89 (direct)TCP port 179
Administrative distance110eBGP 20, iBGP 200
ConvergenceFast (sub-second with BFD)Slow by default, fast with tuning
ScalabilityUp to a few hundred routers per areaHundreds of thousands of routes
Best forEnterprise LAN, campus, internal WANInternet routing, multi-homing, data centre fabric, SD-WAN overlay
Configuration effortLow to mediumMedium to high
Memory/CPU costModerate (LSDB per area)High (full Internet table: 950K+ IPv4 routes in 2026)

Now let’s break down what these differences actually mean for your network design decisions.

What OSPF Actually Does

OSPF (Open Shortest Path First) is a link-state routing protocol defined in RFC 2328 for IPv4 and RFC 5340 for IPv6. Every OSPF router builds a complete map of the network, called the Link-State Database (LSDB), and runs Dijkstra’s Shortest Path First algorithm against that map to calculate the best route to every destination.

The key word is inside. OSPF assumes every router in the network is friendly, exchanges identical information, and follows the same rules. It’s designed for one organisation, one administrative domain, one Autonomous System.

What OSPF is good at:

  • Fast convergence. When a link fails, OSPF floods the change across the area in milliseconds. With Bidirectional Forwarding Detection (BFD), sub-50ms failover is routine.
  • Automatic best-path selection. You don’t write policy. You set interface costs, and OSPF picks the lowest-cost path.
  • Equal-cost multi-pathing (ECMP). OSPF load-balances across equal-cost paths out of the box.
  • Hierarchical design. Areas let you contain LSA flooding and reduce LSDB size on spoke routers.

Where OSPF breaks down:

  • Past roughly 300-500 routers per area, the LSDB gets heavy and SPF runs start eating CPU.
  • No native policy control. You can’t say “prefer this path during business hours, that path overnight” without ugly hacks.
  • Every router sees every link change. Noisy links anywhere hit the whole area.

What BGP Actually Does

BGP-4 (Border Gateway Protocol, RFC 4271) is how the Internet itself routes. Every Autonomous System on the Internet – your ISP, your cloud provider, your company if you’re multi-homed – gets an AS number and peers with its neighbours over TCP port 179.

BGP doesn’t care about bandwidth or delay. It cares about policy. When a BGP router hears about a route, it runs that route through a best-path selection process involving up to 13 attributes (LOCAL_PREF, AS_PATH length, origin, MED, eBGP over iBGP, IGP cost, router ID, and so on) before deciding whether to install it and whether to advertise it to anyone else.

What BGP is good at:

  • Massive scale. The full Internet routing table is over 950,000 IPv4 prefixes and climbing as of April 2026. BGP handles it.
  • Policy control. You decide which routes to accept, which to prefer, which to announce, and to whom. This is what makes multi-homing, traffic engineering, and peering agreements possible.
  • Stability. BGP is deliberately slow to react. A flapping link in Asia shouldn’t trigger routing churn in Europe. Route dampening and MRAI timers smooth out noise.
  • Security (finally). RPKI Route Origin Validation now protects roughly 75% of global IP traffic by destination, even though only about 6.5% of end users are on networks that actively filter invalid routes.

Where BGP breaks down:

  • Default convergence is glacial. 60-second keepalives, 180-second hold timers. Without tuning, you’ll notice outages.
  • Configuration is verbose. A typical eBGP peering with prefix lists, route maps, and community filters runs 50+ lines.
  • No automatic best-path. If you want traffic engineering, you write it.

The Decision Framework: Which One Do You Need?

Stop comparing features. Ask these four questions instead.

1. Is the routing inside or between organisations?

Inside your own AS → OSPF (or EIGRP, or IS-IS).
Between your AS and someone else’s AS → BGP, always.

There is no scenario where you run OSPF between your AS and your ISP. That’s not what OSPF is for. ISPs won’t peer with you using OSPF because they don’t trust your network map, and you shouldn’t want to import theirs.

2. Do you need policy control?

If you need to say “prefer the Bell link during the day, the Rogers link overnight” or “don’t advertise this prefix to that peer,” you need BGP. OSPF doesn’t do policy. It does math.

3. How big is the network?

Under 50 routers, single site: OSPF is overkill-free and just works.
50-500 routers, multi-site enterprise: OSPF with multiple areas, or IS-IS if you’re in a service provider mindset.
500+ routers, multi-tenant data centre, or Internet-facing: BGP, often with EVPN.

Modern hyperscale data centres (Google, Meta, AWS) run BGP all the way to the top-of-rack switch, using eBGP between leaf and spine. OSPF doesn’t scale to that shape.

4. Are you connecting to the Internet or a cloud provider?

If yes, BGP. Every ISP, every Direct Connect, every ExpressRoute, every Interconnect uses BGP. There’s no alternative.

Running Both: How OSPF and BGP Actually Work Together

Here’s what most real enterprise networks look like.

             Internet
                │
         ┌──────┴──────┐
         │ Edge Router │ <- eBGP with ISP
         │ AS 65001    │
         └──────┬──────┘
                │ iBGP + OSPF redistribution
         ┌──────┴──────┐
         │  Core OSPF  │
         │  Area 0     │ <- OSPF carries internal routes
         └──────┬──────┘
         Campus + branches

The edge routers speak BGP to the outside world. They speak OSPF (or iBGP, or both) to the internal core. They redistribute selectively. A default route from BGP into OSPF. Specific internal prefixes from OSPF into BGP if you’re advertising to the Internet.

This pattern is what you’ll build in an Network Engineer career program, and it’s a day-one reality in any mid-size or larger enterprise.

Administrative Distance: Why BGP Wins Ties

When a router learns the same destination from two protocols, administrative distance (AD) decides which wins.

ProtocolDefault AD
Connected0
Static1
eBGP20
OSPF110
IS-IS115
RIP120
iBGP200

eBGP at 20 beats OSPF at 110. This matters when an edge router learns the same prefix from an external BGP peer and from the internal OSPF core. eBGP wins, so external paths take precedence on edge devices. iBGP at 200 loses to OSPF, which is why the typical design uses OSPF as the IGP for iBGP next-hop reachability.

If you’re preparing for certification exams, memorise this table. It shows up on the CCNA certification exam and it’s a favourite interview question.

Convergence: OSPF Is Faster, But BGP Can Catch Up

Untuned defaults paint a clear picture:

  • OSPF: 40-second dead interval, sub-second SPF, total failover in 1-3 seconds on most platforms.
  • BGP: 60-second keepalive, 180-second hold timer. Failover can take 3 minutes.

But nobody runs BGP with defaults in 2026. Modern enterprise and data centre deployments tune:

  • Keepalive to 3 seconds, hold timer to 9 seconds.
  • BFD on every BGP session, detecting failures in under 50 milliseconds at the hardware level.
  • BGP PIC (Prefix Independent Convergence) for sub-second failover on Cisco IOS XR and similar.

With BFD, the convergence gap between OSPF and BGP closes. You can get sub-second failover on both.

BGP vs OSPF vs EIGRP: Where Does EIGRP Fit?

If you’re searching bgp vs ospf vs eigrp, the honest answer is that EIGRP is the odd one out in 2026.

EIGRP is a Cisco-developed advanced distance-vector protocol (technically a hybrid, using DUAL instead of Bellman-Ford). It opened up in 2013 as informational RFC 7868, but adoption outside Cisco-only shops has been limited.

Use CaseWinner
Cisco-only enterprise, simple configEIGRP
Multi-vendor enterpriseOSPF
Internet, multi-homing, data centre fabricBGP
Service provider backboneIS-IS or OSPF, with BGP overlay

Most new enterprise networks we see standardise on OSPF for the IGP (because it’s vendor-neutral) and BGP everywhere else. EIGRP still ships in many environments, but it’s a legacy choice when you have a Cisco-only green field today.

The CCNA vs CCNP decision often comes down to how deep you want to go with these protocols – CCNA covers OSPF basics and touches EIGRP, CCNP ENARSI dives into BGP, advanced OSPF, and EIGRP in detail.

Real Configuration Examples

Let’s see both protocols in action on Cisco IOS. These are the minimum-viable configs you need to get routing working.

Basic OSPF on Two Routers

R1:

router ospf 1
 router-id 1.1.1.1
 network 10.0.12.0 0.0.0.255 area 0
 network 10.1.1.0 0.0.0.255 area 0
 passive-interface default
 no passive-interface GigabitEthernet0/0

R2:

router ospf 1
 router-id 2.2.2.2
 network 10.0.12.0 0.0.0.255 area 0
 network 10.2.2.0 0.0.0.255 area 0
 passive-interface default
 no passive-interface GigabitEthernet0/0

That’s it. The adjacency forms in seconds. Routes propagate automatically. No policy, no filters, no surprises.

Basic eBGP Peering With an ISP

Your edge router (AS 65001):

router bgp 65001
 bgp router-id 192.0.2.1
 neighbor 203.0.113.1 remote-as 64500
 neighbor 203.0.113.1 description ISP-A
 neighbor 203.0.113.1 password cisco123
 neighbor 203.0.113.1 timers 3 9
 neighbor 203.0.113.1 prefix-list FROM-ISP in
 neighbor 203.0.113.1 prefix-list TO-ISP out
 neighbor 203.0.113.1 fall-over bfd
 !
 address-family ipv4
  network 198.51.100.0 mask 255.255.255.0
  neighbor 203.0.113.1 activate
 exit-address-family

ip prefix-list TO-ISP seq 10 permit 198.51.100.0/24
ip prefix-list FROM-ISP seq 10 deny 198.51.100.0/24 le 32
ip prefix-list FROM-ISP seq 20 permit 0.0.0.0/0 le 32

bfd interval 50 min_rx 50 multiplier 3

Notice the difference. OSPF says “here’s my network, talk to the neighbours.” BGP says “here’s my AS, here are the credentials, here are the timers, here’s what I’ll accept from you, here’s what I’ll send you, and here’s how I’ll detect if you go down.” Policy, policy, policy.

When NOT to Use BGP

BGP is powerful, which means it’s also easy to misuse. Don’t use BGP if:

  • You’re routing inside a single campus with fewer than 50 routers. OSPF (or even static routing with HSRP) is simpler and just as reliable.
  • You don’t have a team that understands AS_PATH, LOCAL_PREF, and MED. A misconfigured BGP session can black-hole your Internet link or, worse, leak routes that cause outages for your neighbours.
  • You only have one uplink. Single-homed networks usually don’t need BGP. A static default route to the ISP works fine.

When NOT to Use OSPF

OSPF isn’t always the right IGP either. Skip it if:

  • You’re running a Clos fabric (leaf-spine) with more than a few dozen devices. Leaf-spine BGP designs scale better and give you per-rack failure isolation.
  • You need strong policy control between internal departments or tenants. Use iBGP with route reflectors instead.
  • You’re in a pure MPLS-VPN service provider context. IS-IS with BGP is the standard there.

The Modern Context: BGP in Data Centres and SD-WAN

Two big shifts have changed the 2026 answer to when to use BGP vs OSPF.

1. BGP in the data centre. The classic “BGP is only for the Internet” rule broke a decade ago. Hyperscalers now run eBGP between every leaf and spine switch, using private AS numbers and unnumbered interfaces. RFC 7938 formalised the design. If you’re touching EVPN-VXLAN fabric, you’re running BGP inside the data centre.

2. SD-WAN overlays. Cisco SD-WAN, Versa, VMware VeloCloud, and every other SD-WAN product uses BGP (often alongside OMP or a proprietary control plane) to exchange routes between branch sites over an IPsec overlay. The underlay might be OSPF, but the overlay is BGP.

These patterns are why our Cisco SD-WAN training and CCIE Enterprise Infrastructure program spend heavy hours on BGP, including eBGP in the data centre, iBGP with route reflection, BGP communities, and BGP with BFD tuning.

BGP vs OSPF Interview Questions (Quick Prep)

If you’re here for interview prep, these eight questions show up constantly.

  1. What’s the main difference between BGP and OSPF? OSPF is an IGP using link-state within one AS. BGP is an EGP using path-vector between ASes.
  2. Why does iBGP have a higher AD than OSPF? So the router prefers the internal IGP path to reach the iBGP next-hop, avoiding routing loops.
  3. Can you run OSPF between your AS and your ISP? No, and you shouldn’t want to. BGP is the only practical choice.
  4. Is BGP faster than OSPF? No, OSPF converges faster by default. BGP with BFD closes the gap.
  5. What’s a split-horizon rule in iBGP? An iBGP-learned route is not re-advertised to another iBGP peer. That’s why you need a full mesh or route reflectors.
  6. Can OSPF handle the full Internet routing table? No. OSPF’s LSDB isn’t designed for 950K+ external prefixes. BGP is.
  7. What’s the OSPF cost for a 10 Gbps link with default reference bandwidth (100 Mbps)? 1. All links at or above 100 Mbps get cost 1 unless you change the reference bandwidth.
  8. What are the BGP best-path selection attributes in order? WEIGHT (Cisco-only), LOCAL_PREF, locally originated, AS_PATH length, origin, MED, eBGP over iBGP, IGP metric to next-hop, oldest path, lowest router ID, lowest cluster list length, lowest neighbour IP.

Frequently Asked Questions

What is the difference between BGP and OSPF?

OSPF is an interior routing protocol that builds a complete link-state map of your network and picks the lowest-cost path using Dijkstra’s algorithm. BGP is an exterior routing protocol that exchanges routes between networks using TCP port 179 and picks paths based on configurable policy attributes, not bandwidth. OSPF works inside one organisation. BGP works between them.

Is BGP faster than OSPF?

No. OSPF converges faster than BGP by default, reacting to link failures in seconds versus the 60-180 seconds BGP takes out of the box. With BFD enabled, both can converge in under 50 milliseconds, so in modern well-tuned networks the gap is effectively gone.

Why is BGP preferred over OSPF for the Internet?

BGP scales to hundreds of thousands of routes, supports granular policy between independent administrative domains, and doesn’t require every router on the Internet to share a complete network map. OSPF would collapse under the scale and would force every AS to trust every other AS’s topology, which is unacceptable between competing networks.

Can I use OSPF and BGP at the same time?

Yes, and most enterprise networks do exactly that. OSPF handles internal routing, BGP handles connections to ISPs, cloud providers, and business partners. The two protocols are redistributed selectively at edge routers, usually with a default route going from BGP into OSPF and specific prefixes going from OSPF into BGP.

What is the administrative distance of OSPF and BGP?

OSPF has an administrative distance of 110. eBGP has an AD of 20, meaning externally learned BGP routes beat OSPF routes when a router hears the same prefix from both. iBGP has an AD of 200, which loses to OSPF – this is intentional so that internal IGP paths are preferred for reaching iBGP next-hops.

Is BGP still relevant today?

Yes, more than ever. As of April 2026, BGP carries the full Internet routing table (950K+ IPv4 prefixes, 200K+ IPv6), runs every major data centre fabric, and drives every SD-WAN and cloud interconnect. Security upgrades through RPKI Route Origin Validation now protect about 75% of IP traffic by destination. BGP is a core skill for any serious network engineer in 2026.

Do I need to learn both BGP and OSPF?

Yes, if you’re targeting network engineer, cloud networking, or any Cisco professional certification. CCNA covers OSPF and introduces BGP basics. CCNP ENARSI goes deep on both. CCIE Enterprise Infrastructure expects expert-level command of OSPF multi-area, BGP policy, and redistribution between them.

Key Takeaways

  • OSPF is for routing inside one administrative domain. Fast, automatic, scales to a few hundred routers per area.
  • BGP is for routing between administrative domains, large data centres, and any Internet-facing deployment. Policy-rich, massively scalable, needs careful configuration.
  • Use OSPF for campus, branch, and internal WAN. Use BGP for Internet peering, multi-homing, data centre fabric, SD-WAN overlays, and cloud interconnect.
  • Administrative distance decides ties: eBGP (20) beats OSPF (110) beats iBGP (200).
  • Real networks run both. OSPF in the core, BGP at the edge and in the overlay. Master the redistribution boundary and you’ve mastered enterprise routing.

If you’re ready to move from theory to hands-on fluency, the CCIE Enterprise Infrastructure training at SMEnode Academy walks you through every BGP and OSPF scenario you’ll see on the exam and in production. For career context, see how to become a network engineer in 2026.