BGP

BGP vs OSPF — Key Differences and When to Use Each

J Jaspreet Singh July 17, 2025 6 min read
BGP vs OSPF 24 Key Differences
BGP (Border Gateway Protocol) is an Exterior Gateway Protocol (EGP) used to route traffic between different Autonomous Systems — it is the routing protocol of the internet. OSPF (Open Shortest Path First) is an Interior Gateway Protocol (IGP) used to route traffic within a single AS. They serve completely different purposes and are often deployed together.
Key takeaways

  • BGP = EGP (between ASes) | OSPF = IGP (within one AS) — fundamentally different purposes
  • BGP uses path-vector algorithm | OSPF uses Dijkstra's link-state algorithm
  • BGP convergence is slow (minutes) | OSPF converges fast (seconds)
  • BGP scales to handle 900,000+ internet routes | OSPF works best within a single organization
  • BGP uses TCP port 179 | OSPF uses IP protocol 89 (multicast 224.0.0.5 / 224.0.0.6)
  • BGP chooses paths based on policy attributes | OSPF chooses shortest path based on cost/bandwidth
  • In enterprise networks: OSPF handles internal routing, BGP handles ISP peering

These two protocols get compared constantly, but they are not competitors — they solve different problems at different scales.

  • OSPF is an interior gateway protocol. It runs inside one organisation’s network and answers: what is the fastest path to this destination?
  • BGP is an exterior gateway protocol. It runs between organisations and answers: which of these paths do I want to use, and what am I willing to tell others about mine?

OSPF optimises. BGP negotiates. That is the whole distinction, and almost every other difference follows from it.

Full Comparison

OSPFBGP
TypeIGP — interiorEGP — exterior
AlgorithmLink-state (Dijkstra SPF)Path-vector
ScopeWithin one autonomous systemBetween autonomous systems
TransportIP protocol 89, directTCP port 179
Neighbour discoveryAutomatic via multicast hellosManual — every peer configured explicitly
Path selectionLowest cost (bandwidth-derived)Best-path algorithm, ~13 tie-breakers
MetricCost — a single numberAttributes: weight, local preference, AS-path, MED, origin
ConvergenceSecondsTens of seconds to minutes
Routing table sizeHundreds to a few thousand1,000,000+ in the global table
Topology knowledgeFull map of the areaOnly the AS path, not the internal topology
Administrative distance11020 (eBGP) / 200 (iBGP)
Policy controlMinimalExtensive — the entire point
AuthenticationMD5, SHAMD5, TCP-AO
Loop preventionSPF over a complete link-state databaseAS-path — reject any route already containing your own ASN
HierarchyAreas, with a mandatory area 0 backboneRoute reflectors and confederations

How Each One Chooses a Path

OSPF: shortest cost wins

Every router floods link-state advertisements describing its own links. Every router in the area therefore holds an identical database — a complete map. Each then runs Dijkstra’s algorithm against it to compute a shortest-path tree rooted on itself.

Cost is derived from bandwidth: reference bandwidth ÷ interface bandwidth. The default reference of 100 Mbps means every link at 100 Mbps and above scores a cost of 1, so a gigabit link and a 100 Gbps link look identical. On any modern network you should raise it:

Router(config-router)# auto-cost reference-bandwidth 100000

This must be set identically on every router in the area, or path selection becomes inconsistent.

BGP: policy wins, and cost is not considered at all

BGP does not know or care about bandwidth, latency or link speed. It walks an ordered list of attributes and stops at the first one that breaks the tie:

  1. Weight — Cisco-proprietary, local to one router, highest wins
  2. Local preference — highest wins, shared across the AS. The standard tool for choosing your outbound path.
  3. Locally originated routes
  4. Shortest AS-path — the classic tie-breaker
  5. Lowest origin type (IGP < EGP < Incomplete)
  6. Lowest MED — a hint to a neighbouring AS about which of your entry points to prefer
  7. eBGP over iBGP
  8. Lowest IGP metric to the next hop
  9. Oldest route, then lowest router ID, then lowest neighbour address

The practical consequence: BGP will happily choose a slow, congested path over a fast one if the AS-path is shorter. It is optimising for policy and reachability, not performance.

How They Work Together

A multi-homed organisation runs both, and they have distinct jobs:

  • OSPF carries internal routes and, critically, provides reachability to BGP’s next-hop addresses. Without a working IGP, iBGP routes are learned but not installed because the next hop is unreachable.
  • BGP carries external routes and enforces which provider you use for what.

The standard practice is not to redistribute the full BGP table into OSPF. A million routes will destroy an OSPF process. Instead, internal routers get a default route pointing at the BGP-speaking edge, and only the edge holds the full table.

Which Should You Use?

SituationUse
Routing inside a campus or data centreOSPF (or IS-IS, or eBGP in modern spine-leaf fabrics)
Single internet connectionNeither — a default static route is sufficient
Two connections to one ISPUsually still static plus a floating static backup
Two or more different ISPsBGP — you need your own ASN and address space
You must control which provider inbound traffic usesBGP — nothing else can do this
Connecting to a partner or cloud providerBGP — AWS Direct Connect, Azure ExpressRoute and equivalents all use it
Large modern data centre fabriceBGP everywhere, increasingly, for its scaling and policy control

The most common mistake is deploying BGP for a single-homed connection. If you have one provider, there is no path decision to make and a default route does the job with none of the complexity.

Operational Realities

OSPF is easier to break badly. A flapping link floods LSAs to every router in the area, each of which reruns SPF. Areas exist to contain this blast radius, and skipping the hierarchy on a large flat network causes CPU problems that appear only under failure conditions.

BGP is easier to break publicly. A misconfigured BGP filter can leak routes to the internet and black-hole traffic for networks that are not yours. Prefix filters, maximum-prefix limits and RPKI validation are not optional on an internet-facing BGP session.

Router(config-router)# neighbor 203.0.113.1 maximum-prefix 500 90 warning-only

Convergence differs by an order of magnitude. OSPF reconverges in seconds. BGP is deliberately slow — dampening, timers and the MRAI interval exist to keep the global table stable, not to be fast. A backup path via BGP will not fail over as quickly as one via OSPF.

Frequently Asked Questions

Can BGP replace OSPF?

Inside a data centre fabric, increasingly yes — eBGP-everywhere designs are common. In a general enterprise network, no: BGP has no automatic neighbour discovery, converges far more slowly, and does not select paths on link speed.

Which is faster?

OSPF converges much faster. BGP’s slowness is intentional, to keep the internet’s routing table from oscillating.

Do I need BGP for two internet connections?

Only if they are to different providers and you need the same public addresses to work over either. Two links to one ISP, or two links where you can tolerate different public addresses, are handled with static routes and NAT.

Why does BGP use TCP?

Because the table is large and must be reliably delivered, and because peers are often not directly connected. TCP handles retransmission, ordering and connection management so BGP does not have to. OSPF runs directly over IP and implements its own reliability, which works because neighbours are always adjacent.

What is the difference between iBGP and eBGP?

eBGP peers with a different AS number; iBGP peers within the same one. eBGP has AD 20 and decrements TTL; iBGP has AD 200, does not advertise routes learned from one iBGP peer to another (requiring a full mesh, route reflectors or confederations), and does not change the next hop by default.

Should I redistribute BGP into OSPF?

Almost never for the full table — it will overwhelm OSPF. Redistribute a default route or a small set of summaries instead, and keep the full table on the edge routers that need it.

What about EIGRP?

EIGRP is another IGP, comparable to OSPF rather than BGP. See EIGRP vs OSPF for that comparison.

JA
Written by

Jaspreet Singh

Hey! I'm Jaspreet Singh and I completed a degree in Bachelor of Computer Applications. I have 7+ years of experience in the Network & Security Domain as well as the Cloud Infra Domain. So I love to explore my technical knowledge with you.

Leave a Reply

Your email address will not be published. Required fields are marked *