SKNK Technical Guide
BGP Basics: How the Internet Learns Where to Send Traffic
Learn how Border Gateway Protocol (BGP) enables thousands of independent networks to exchange routing information and keep the Internet connected.
Technical content
Written and maintained by Shikanoko NetworksIntroduction
Every time you visit a website, stream a video, or send an API request, your traffic may cross several independent networks before reaching its destination.
Your local Internet provider doesn't own the entire Internet.
Neither does your cloud provider.
Neither does the company hosting the application you're trying to reach.
Your traffic travels across thousands of independently operated networks that continuously exchange routes with one another.
So how do thousands of independent networks coordinate?
The answer is the Border Gateway Protocol.
BGP is the routing protocol used by Autonomous Systems (ASes) to exchange reachability information across the public Internet. It tells routers which networks can reach which IP prefixes, and which path should be used to get there.
Without BGP, today's Internet would not scale beyond isolated networks. Every Internet Service Provider would have to manually maintain routes to every other network — a task that becomes impossible as the Internet continues to grow.
In this guide, you'll learn:
- What BGP is and why the Internet needs it
- How BGP advertises routes between networks
- How routers choose one route over another
- Why the shortest path isn't always the fastest
- Where BGP fits into modern Internet infrastructure
New to Autonomous Systems? Start with What Is an ASN?.
What Is BGP?
Border Gateway Protocol is the standard used to exchange routes between Autonomous Systems.
Unlike OSPF or IS-IS, which handle routing within a single organization, BGP operates between independently managed networks. This is why it's called an inter-domain routing protocol.
Every major ISP, cloud platform, CDN, and Internet exchange relies on BGP to tell neighboring networks which IP prefixes it can reach.
BGP does not carry your packets. It tells routers how to build the routing table that will later be used to forward those packets.
Why Doesn't the Internet Use Static Routes?
Imagine there were no BGP.
Every provider would have to manually configure routes to every other network on Earth. Every time a new network joined the Internet, every other network would need to update its routing tables manually. Every time an existing network changed providers, everyone else would have to update their configurations again.
That approach might work for a handful of networks. It breaks down when the Internet consists of tens of thousands of Autonomous Systems.
BGP solves this by letting each network advertise the prefixes it can reach. Neighbors learn those routes automatically and propagate them further.
No central authority. No manual configuration. Just networks telling other networks what they can reach.
How BGP Actually Works
BGP works by exchanging route advertisements between neighboring Autonomous Systems.
Imagine a cloud provider that owns the IP prefix 203.0.113.0/24. It advertises that prefix to its neighbors together with its ASN:
203.0.113.0/24
Origin: AS64500
Think of this as the network saying: "If you're trying to reach this prefix, send the traffic to me."
The neighboring network adds its own ASN before advertising the route further:
AS64500 → AS65123 → AS65333
Eventually, thousands of routers around the world learn that traffic for 203.0.113.0/24 can be reached through that sequence of Autonomous Systems.
BGP is advertising routes, not forwarding traffic. Forwarding happens later, after routers have selected the most appropriate path from the information BGP has collected.
Three Core Concepts Behind Every BGP Route
Real BGP updates include many attributes. Three concepts are enough to understand how Internet routing works.
IP Prefix
The destination network being advertised. Example: 203.0.113.0/24. This tells routers what network is reachable.
Origin ASN
The Autonomous System that originally announced the prefix. This identifies which network owns or originates the route.
AS Path
As routes propagate, each Autonomous System adds its own ASN. A route might eventually look like:
AS64500 → AS65123 → AS65333 → Your ISP
This sequence is the AS Path. It lets routers understand how a destination can be reached, and it helps prevent routing loops. All else being equal, a shorter AS Path is generally preferred — but that's only one factor among many.
How Routers Choose the Best Route
A router often learns multiple paths to the same destination. A cloud provider may connect to several upstreams. An ISP may peer with multiple exchanges. A single prefix may be reachable through several different Autonomous Systems at once.
BGP evaluates the available routes and selects what it considers the best path. "Best" does not mean shortest or fastest. Routers evaluate a series of attributes according to their configured policies.
The exact decision process varies between routing implementations, but the concepts below explain the majority of routing decisions encountered in practice.
Local Preference
Local Preference tells routers which outbound path to prefer when multiple options exist.
An ISP connected to two transit providers might prefer one because of lower costs, better capacity, existing peering agreements, or internal policies. Even if another path contains fewer Autonomous Systems, Local Preference may override it.
Internet routing is influenced by business decisions as much as technical ones.
AS Path
All else being equal, a shorter AS Path is generally preferred. But a route with a longer AS Path may still win if higher-priority attributes point elsewhere.
MED (Multi-Exit Discriminator)
When two networks connect through multiple physical links, MED allows one network to suggest which entry point it would prefer for incoming traffic. MED is a suggestion — the neighboring network may ignore it.
Next Hop
Every route contains a Next Hop — the router where packets should be forwarded. Without a reachable Next Hop, the route cannot be used, even if every other attribute appears valid.
Why the Shortest Path Isn't Always the Fastest
Packets don't always take the shortest path. They often don't.
Route A — AS Path length: 2
Your ISP → Transit Provider → Destination
Route B — AS Path length: 3
Your ISP → Regional Exchange → Cloud Network → Destination
Route A has the shorter AS Path. Route B may provide lower latency.
Why? Because routing isn't based solely on distance. Operators also consider peering relationships, transit costs, available bandwidth, congestion, business agreements, and traffic engineering policies.
The path with fewer Autonomous Systems isn't always the one that delivers packets fastest. This is why traceroute results sometimes look surprising — the "longer" route may perform better.
Why BGP Routes Change
Routers don't calculate a route once and keep using it forever. BGP continuously exchanges updates as conditions change.
Common triggers: a new peering relationship is established, an upstream provider experiences an outage, a link goes offline for maintenance, routing policies are adjusted, a new prefix is announced, or an existing route is withdrawn.
Most of these changes happen automatically. The goal is simple: maintain reachability as the Internet shifts from moment to moment.
Is BGP Secure?
BGP was designed to exchange routes, not to verify whether every announcement is legitimate. As the Internet grew, this created room for accidental misconfigurations and, in rare cases, malicious announcements.
Route Leaks
A network advertises routes beyond the intended scope. Traffic may follow unexpected paths.
BGP Hijacking
A network incorrectly advertises prefixes that belong to another organization. Traffic may be redirected, intercepted, or dropped.
How Modern Networks Improve Routing Security
Today, many operators use Resource Public Key Infrastructure (RPKI) to validate whether an ASN is authorized to originate a specific prefix. Instead of trusting every announcement, routers can check whether the origin ASN matches published Route Origin Authorizations (ROAs).
RPKI doesn't solve every routing security problem. It significantly reduces the risk of common origin-related incidents.
BGP vs OSPF
BGP and OSPF are both routing protocols. They solve fundamentally different problems.
| Feature | BGP | OSPF |
|---|---|---|
| Scope | Between Autonomous Systems | Within a single Autonomous System |
| Scale | Global — tens of thousands of networks | Enterprise — hundreds to thousands of routers |
| Type | Path Vector | Link State |
| Decides | Which AS to send traffic through | The fastest internal path |
| Typical use | ISP peering, cloud routing, multi-homing | Enterprise networks, campus networks, data centers |
BGP and OSPF often work together: OSPF handles routing inside an organization, while BGP handles routing between that organization and the rest of the Internet.
Do You Actually Need BGP?
Most organizations never need to run BGP themselves.
If your applications run on a cloud platform, a managed hosting provider, or behind a CDN, Internet routing is already handled for you.
BGP becomes valuable when your organization wants to connect to multiple upstream providers, announce its own IP prefixes, operate independent routing policies, build Anycast services, or increase resilience across multiple locations.
In those situations, BGP lets your network participate directly in global Internet routing.
Thinking about getting your own ASN? Read How to Get Your Own ASN: A Complete Guide.
Frequently Asked Questions
Is BGP faster than OSPF?
Not necessarily. They solve different problems. OSPF handles routing within a single organization. BGP exchanges routes between independently managed networks.
Does BGP improve latency?
Not by itself. Latency depends on physical distance, congestion, peering relationships, and network topology. BGP provides the information routers use to make forwarding decisions.
Why is BGP called a path vector protocol?
Because BGP advertises the sequence of Autonomous Systems a route has passed through. This AS Path enables routing decisions and prevents loops.
Do I need my own ASN to use BGP?
External BGP requires Autonomous System Numbers — routes are exchanged between ASes. Internal BGP operates within a single AS using that organization's existing ASN.
What's the difference between eBGP and iBGP?
eBGP runs between different Autonomous Systems for inter-domain routing. iBGP runs between routers within the same AS to distribute external routes internally.
Conclusion
Every second, countless BGP updates help routers determine how traffic should move across the Internet.
Yet every website you visit, every cloud application you use, and every API request you send depends on Autonomous Systems exchanging routes through BGP.
BGP doesn't simply connect networks. It allows independently operated networks to cooperate without central coordination. That's one of the reasons the modern Internet can continue to scale.
Understanding BGP isn't about memorizing attributes or configuration commands. It's about understanding how thousands of independent networks cooperate to form a single global Internet.
Key Takeaways
- BGP enables independently operated networks to exchange routing information across the Internet.
- BGP advertises routes — it does not forward traffic itself.
- Routers choose paths based on Local Preference, AS Path, MED, and Next Hop — not just the shortest route.
- The shortest AS Path doesn't guarantee the fastest path. Peering, costs, capacity, and congestion all matter.
- Most organizations don't need to run BGP — cloud providers and ISPs handle routing for them.
- RPKI helps validate route announcements, reducing the risk of BGP hijacking and route leaks.
Continue Reading
- What Is an ASN? A Complete Beginner's Guide — learn how Autonomous Systems identify networks on the Internet.
- How to Get Your Own ASN: A Complete Guide — understand application paths, requirements, and costs.
- €89 vs €2,850: The Real Cost of Running Your Own ASN — a detailed cost breakdown of ASN ownership in Europe.
- RIPE NCC vs LIR Sponsorship: What Nobody Tells You — which registration path actually makes sense for your organization.