Black Friday: 50% off every workbook with code . Ends Nov 30, 23:59 ET. Buy Now

Last day: 50% off every workbook ends tonight at 23:59 ET. Code Buy Now

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

OSPF routes inside your network. BGP routes between networks. Here's every practical difference, with config snippets and a decision framework you can apply today.
13min
Read Time
Network switch with blue Ethernet cables plugged into its ports, used for the BGP vs OSPF guide
OSPF routes inside your network. BGP routes between networks. Here's every practical difference, with config snippets and a decision framework you can apply today.

BGP vs OSPF comes down to one question: is the routing inside your network or between networks? Use OSPF inside your own network for fast, automatic routing between your routers. Use BGP to connect to the internet, peer with another organisation, or run a large 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 once.

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. New to BGP’s path-selection logic specifically? Our BGP Multi-Exit Discriminator guide is a good next stop after this one.

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
ScalabilityLimited by CPU, area type and route countOver 1M IPv4 prefixes (the full internet table)
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: over 1 million IPv4 routes in 2026)

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

BGP vs OSPF scope sketch: OSPF with four routers inside one boundary, BGP with two boundaries joined by a single turquoise link
OSPF routes inside one network, one Autonomous System. BGP routes between separate networks, and the link between them is where policy lives.

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. OSPFv3 runs over IPv6 link-local addresses and the multicast groups ff02::5 and ff02::6. 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. Neighbours move through seven states on the way to exchanging routes (Down, Init, 2-Way, ExStart, Exchange, Loading, Full), which our What Is OSPF guide walks through.

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), a failure is detected in about 150 ms (50 ms x 3), so failover is typically sub-second.
  • 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:

  • As an area grows, the LSDB gets heavy and SPF runs start eating CPU. Older Cisco guidance suggested about 50 routers per area. Modern routers cope with far more, so the real limit depends on CPU, area type and route count.
  • 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. The protocol itself is specified in RFC 4271.

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 passed 1 million IPv4 prefixes in late 2025 and keeps growing.
  • 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, slowly improving. About 67% of announced prefixes now have a signed Route Origin Authorization (Hurricane Electric, 2026-07-26), but only roughly a quarter of networks actively reject invalid routes (APNIC).

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, use OSPF (or EIGRP, or IS-IS). Between your AS and someone else’s AS, use 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 this link during the day, that one 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?

SizeRecommendation
Under 50 routers, single siteOSPF is enough and just works
50-500 routers, multi-site enterpriseOSPF with multiple areas, or IS-IS if you’re in a service provider mindset
500+ routers, multi-tenant data centre, or internet-facingBGP, often with EVPN

Modern hyperscale data centres 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 cloud interconnect uses BGP. There’s no alternative.

Running Both: How OSPF and BGP Actually Work Together

A cloud joined to an EDGE router by a turquoise eBGP link, the EDGE router linked by OSPF to a CORE router that feeds two switches
The turquoise link is the eBGP session to the ISP. The navy links are OSPF inside the network. The EDGE router sits on the boundary, where the two protocols meet.

Here’s what most real enterprise networks look like. 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, and specific internal prefixes from OSPF into BGP if you’re advertising to the internet.

This pattern is a day-one reality in any mid-size or larger enterprise, and it’s worth building once in a lab before you meet it in production. Four rules keep the boundary safe:

  • Never redistribute the full BGP table into OSPF. Send OSPF a default route instead, with default-information originate on the edge router.
  • Redistribute OSPF into BGP only through a route-map and a prefix-list, so the internet only hears the prefixes you own.
  • Run iBGP between loopbacks so the session survives a single link failure, and use next-hop-self on the edge so internal peers can reach the next hop.
  • If you redistribute in both directions, tag the routes you inject so they can’t come back and form a loop.
router ospf 1
 default-information originate
!
ip prefix-list MY-PREFIXES seq 10 permit 198.51.100.0/24
!
route-map OSPF-TO-BGP permit 10
 match ip address prefix-list MY-PREFIXES
!
router bgp 65001
 address-family ipv4
  redistribute ospf 1 route-map OSPF-TO-BGP

Can iBGP Replace OSPF Inside Your Network?

Sometimes, but not by default. iBGP carries routes between routers in the same AS, but it doesn’t discover neighbours or calculate paths on its own. Each iBGP router still needs a way to reach the next hop, and that’s usually OSPF’s job. That’s why the classic enterprise design is OSPF for reachability plus iBGP for the routes that need policy.

The exception is the data centre. RFC 7938 describes leaf-spine fabrics that run eBGP only, with no IGP at all. If you’re building one, you’re not choosing between OSPF and iBGP. You’re choosing a design where eBGP does both jobs.

Rule of thumb: under about 50 routers and no policy needs, stay with OSPF. Past that, or when you need per-tenant policy, BGP starts to earn its complexity.

Administrative Distance: Which Protocol Wins When Both Know the Route

An EBGP cloud and an OSPF router cluster both send a route to one router; the thick turquoise EBGP arrow wins and a check mark lands in the routing table
Same destination, two sources. The lower administrative distance wins: eBGP 20, OSPF 110, iBGP 200.

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. When an edge router hears the same prefix from an external BGP peer and from the OSPF core, the eBGP route wins. iBGP at 200 loses to OSPF on purpose: if the IGP and iBGP both know a prefix, the IGP route is preferred, which helps prevent loops when routes are redistributed between the two. AD only picks between protocols for the same prefix. It doesn’t decide how an iBGP next hop gets resolved. That’s always done recursively through whatever route the router has to the next-hop address.

If you’re preparing for certification exams, know these values. The CCNA has you read administrative distance in a routing table, and it’s a favourite interview question.

Convergence: OSPF Is Faster, But BGP Can Catch Up

Two panels with a failed link between two routers: DEFAULT shows an hourglass still holding sand in the top, BFD shows a turquoise hourglass nearly drained
Silent failures can take up to 40 seconds to notice with the OSPF dead interval and up to 180 seconds with the BGP hold timer. BFD at 50 ms x 3 detects one in about 150 ms.

Untuned defaults paint a clear picture:

  • OSPF: hello 10 s and dead 40 s on broadcast and point-to-point links. When a link goes down, failover typically takes 1-3 seconds. If the link stays up but the neighbour goes quiet, detection can take up to 40 seconds without BFD.
  • BGP: keepalive 60 s and hold 180 s. A directly connected eBGP session resets as soon as the link drops, but a silent failure can take up to 3 minutes to notice.

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 about 150 ms with 50 ms x 3 timers.
  • BGP PIC (Prefix Independent Convergence) for sub-second failover on platforms that support it.

With BFD, the detection gap between OSPF and BGP closes. Route recalculation comes on top, so total convergence is typically under a second for 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. The short version of BGP vs EIGRP: EIGRP is an IGP built for one Cisco-led domain and picks paths by a composite metric, while BGP is an EGP that picks paths by policy attributes.

EIGRP is a Cisco-developed advanced distance-vector protocol (technically a hybrid, using DUAL instead of Bellman-Ford). Cisco published it as informational RFC 7868 in May 2016, 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 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 on a Cisco-only green field today. Our EIGRP vs OSPF comparison goes deeper on that specific pairing if Cisco-only is actually your environment.

The CCNA vs CCNP decision often comes down to how deep you want to go with these protocols: CCNA configures single-area OSPF and has you read administrative distance in a routing table, but it doesn’t test BGP or EIGRP. CCNP ENCOR adds multi-area OSPF and eBGP between directly connected neighbours.

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 YOUR-MD5-KEY
 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

interface GigabitEthernet0/1
 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

Leaf-spine fabric sketch with two SPINE switches and three LEAF switches; the left leaf is linked to both spines by turquoise lines
Every leaf links to every spine, so any two leaves are two hops apart. The turquoise links are the left leaf’s two uplinks. RFC 7938 describes this design running eBGP.

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 a proprietary control plane) to exchange routes between branch sites over an IPsec overlay. The underlay might be OSPF, but the overlay is BGP. The overlay then steers traffic by application, using application-aware routing in SD-WAN and QoS markings like expedited forwarding (DSCP 46).

Interview Practice: 4 Questions the FAQ Doesn’t Cover

If you’re here for interview prep, these four questions aren’t answered in the FAQ below.

  1. 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.
  2. Can OSPF handle the full internet routing table? No. OSPF’s LSDB isn’t designed for a million-plus external prefixes. BGP is.
  3. 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.
  4. 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.

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, failures are detected in about 150 ms and both can converge in under a second, 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 outdated?

No. BGP carries the full internet routing table (over 1M IPv4 prefixes in 2026, per APNIC’s weekly report), runs most data centre fabrics, and sits under cloud interconnects like AWS Direct Connect and Azure ExpressRoute. It’s a core skill for network engineers.

Do I need to learn both BGP and OSPF?

Yes, if you’re targeting network engineer, cloud networking, or any Cisco professional certification. CCNA has you configure OSPF but doesn’t test BGP. CCNP ENCOR adds multi-area OSPF and eBGP.

Is OSPF still used?

Yes. OSPF is still widely used inside enterprise and campus networks, especially with mixed vendors, and it’s the routing protocol the CCNA has you configure.

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.

Keep Reading

Related Articles

Hands fitting hardware into an open desktop tower, with SMEnode Labs cyan fading in from the bottom-left corner.

How to Install EVE-NG in 2026: 5 Steps for the Free v7 ISO

EVE-NG v7 ships as one ISO with a free 7-node tier. Here's how to install it on VMware, ESXi, Proxmox or bare metal, and the settings that break most installs.
Blurred rows of server drive bays glowing blue in a rack, used for the network automation engineer salary guide

Network Automation Engineer Salary 2026: Skills, Tools and Pay Guide

Network automation engineers earn $109K-$128K on average in the US, with senior roles past $160K. Here's the real pay data by experience, skill and city.

Share Your Valuable Opinions