BGP Basics With Examples: How Internet Routing Really Works

BGP basics with examples: routers exchanging routes between networks
Five practical examples of how BGP works.

BGP Basics With Examples: How Internet Routing Really Works

Border Gateway Protocol (BGP) decides how data moves between the networks that make up the internet. However, most guides stay theoretical, which makes BGP feel harder than it is. In this guide, we cover BGP basics with examples, so you can see each concept in action before you touch a real router.

What BGP Does

BGP is a path-vector protocol. Instead of calculating the fastest link, it shares reachability: each network tells its neighbors which addresses it can deliver to, and through which path. As a result, thousands of independent networks can cooperate without sharing their internal designs.

Autonomous Systems and the AS Path

Each independent network is an autonomous system (AS) with its own number (ASN). Because every router adds its ASN as a route passes through, the route builds up a trail called the AS path.

Example 1: choosing between two paths. Suppose AS 64500 can reach a customer network behind AS 64510 in two ways:

All else being equal, BGP picks Route A, since fewer hops usually means a simpler path. Note that the ASNs in these examples come from the range reserved for documentation, so they are safe to practice with.

eBGP vs iBGP

  • eBGP runs between different autonomous systems, usually between directly connected edge routers.
  • iBGP runs inside one AS and distributes the routes learned at the edge.

However, iBGP does not re-advertise routes learned from other iBGP peers. Therefore, large networks use route reflectors instead of a full mesh of sessions.

Example 2: A Basic eBGP Session

Here is a minimal Cisco-style configuration. Your network (AS 64500) peers with an upstream provider (AS 64501) and announces its own prefix:

One practical tip: the network command only announces a prefix if that exact route already exists in your routing table. Consequently, many beginners wonder why nothing is advertised. A static route to Null0 for the prefix usually solves it.

How BGP Chooses the Best Route

When several routes reach the same destination, BGP compares attributes in a fixed order. On Cisco devices, the first checks are:

OrderAttributeRule
1WeightHigher wins (Cisco only, local to the router)
2Local preferenceHigher wins (shared inside the AS)
3AS path lengthShorter wins
4MEDLower wins
5eBGP over iBGP, then lowest router IDFinal tie-breakers

Example 3: preferring one provider. Imagine two upstreams, ISP-A (AS 64501) and ISP-B (AS 64502). ISP-A is faster, so you want it for outbound traffic. Local preference is the right tool:

Since the default local preference is 100, routes learned from ISP-A now win. Meanwhile, ISP-B stays ready as a backup. If ISP-A fails, traffic shifts automatically.

Example 4: Filtering a Customer

BGP trusts its neighbors by default. Therefore, you should filter what each neighbor may send. Suppose a customer (AS 64520) owns only 198.51.100.0/24:

This setup accepts only the customer’s own prefix, and it shuts the session down if the customer suddenly sends more than 10 routes. As a result, a simple mistake on their side cannot flood your network.

Why Filtering Matters: A Real Case

In 2008, a Pakistani ISP tried to block YouTube locally. However, it announced a more specific prefix for YouTube’s address space, and the announcement leaked to the wider internet. Because BGP prefers the most specific prefix, large parts of the internet sent YouTube traffic to the wrong place for a short time. In short, one unfiltered announcement can affect millions of users.

Fortunately, today you can combine prefix filters with RPKI route origin validation, which checks whether an AS is authorized to announce a prefix.

Example 5: When You Need BGP

A small company with one provider needs only a default route. In contrast, consider a company with its own /24, its own ASN, and two internet providers. Here, BGP lets the company announce its prefix through both links, fail over automatically, and steer traffic with local preference. Likewise, data centers, cloud connections, and ISPs rely on BGP for the same reasons.

Checking Your Work

Two commands help you verify a session:

  • show ip bgp summary shows neighbor state and prefix counts.
  • show ip bgp lists received routes and their attributes.

If a neighbor is stuck in “Active” or “Idle”, first check IP reachability, then the remote ASN, and finally any firewall rules on TCP port 179.

Final Thoughts

In short, BGP shares reachability, compares attributes in order, and follows the policies you set. Therefore, start with small lab examples like the ones above. After that, add filtering and RPKI before connecting to a real provider. With practice, BGP becomes logical rather than intimidating.

Juniper MX204 vs. MX304: Enterprise Edge Router Guide

1 thought on “BGP Basics With Examples: How Internet Routing Really Works”

  1. Pingback: Spanning Tree Protocol : How STP Prevents Network Loops

Leave a Comment

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

Scroll to Top