Blog • SHM Soft

What Is BGP? Border Gateway Protocol Explained

BGP is the protocol that holds the internet together. It lets thousands of independent networks agree on how to reach each other. Here is how it works, in plain English.

Published 28 November 2026 • SHM Soft

The internet is not one network. It is tens of thousands of separate networks, run by different companies, universities, and governments, all connected to each other. There is no central map and no boss. So how does a packet from your home find its way to a server on the other side of the world? The answer is BGP.

BGP stands for Border Gateway Protocol. It is the protocol that networks use to tell each other what they can reach, and it is the reason the internet works as one system instead of thousands of disconnected islands. In this guide, we explain what BGP is, how it works, and why it matters.

Satellite view of Earth at night showing global networks connected by BGP

What Is BGP?

BGP is a routing protocol that runs between autonomous systems. An autonomous system, or AS, is a network under one administration, with its own routing policy. Your internet provider is an AS. Google is an AS. A large university is an AS. Each one has a unique AS number, or ASN, assigned by a regional registry. There are over 70,000 of them, and they are all connected through BGP.

Each AS tells its neighbours which blocks of IP addresses it can reach. These blocks are called prefixes. A neighbour that accepts the route passes it on to its own neighbours, adding its own AS number to the path. In this way, every network learns how to reach every other network, one announcement at a time. The full list of networks a route has passed through is called the AS path, and it is the most important piece of information in BGP.

BGP is a path-vector protocol, which means it advertises the whole path, not just a distance. That is how it avoids loops. If a router sees its own AS number in a path, it knows the route has already passed through its network, so it drops the route. It is a simple rule, and it is what keeps the internet from routing in circles.

How BGP picks the best path

When a BGP router learns several ways to reach the same prefix, it has to pick one. It does this with a list of rules, checked in order, until only one route is left. The first rule is usually local preference, which is a number the network owner sets. A higher local preference wins, and it is how a network expresses its business choices, like preferring a cheaper provider or a faster link. After that, the router prefers the shortest AS path, then the lowest origin code, then the lowest MED, and finally the lowest router ID.

Notice what is missing: BGP does not pick the fastest path in the technical sense. BGP is a policy protocol as much as a technical one. That is why two networks can disagree about the best way to reach the same destination, and both can be right, from their own point of view.

BGP runs over TCP, on port 179, which is unusual for a routing protocol. Most routing protocols use their own transport. BGP uses TCP because it needs reliable delivery, and because it only sends updates when something changes. A BGP session between two routers can stay up for months, sending a small keepalive every 60 seconds, and only sending a full update when a route appears or disappears.

Peering and transit

Networks connect to each other in two main ways. In transit, a smaller network pays a larger network to carry its traffic to and from the whole internet. Your home provider buys transit from a bigger provider, and that provider buys transit from an even bigger one. In peering, two networks agree to exchange traffic directly, for free, usually because they both benefit. Two large providers might peer so their customers can reach each other without going through a third network.

These are business agreements, not just technical ones, and BGP is the tool that carries them out. A network only announces the routes it is willing to carry traffic for. A customer announces its own prefixes to its provider, and the provider announces them to the world. A peer announces only its own customers' prefixes, not the whole internet, because it is not being paid to carry other people's traffic. Getting these announcements wrong is how the internet breaks, which brings us to the most famous BGP story of all.

When BGP Goes Wrong: Route Leaks and Hijacks

BGP trusts what it is told. If a network announces that it can reach a block of addresses, its neighbours believe it, and they pass the announcement on. Most of the time, that trust is fine. But when a network announces something it should not, the results can be dramatic.

The most famous case happened in 2008, when Pakistan Telecom announced that it could reach YouTube's addresses, as part of an attempt to block YouTube inside Pakistan. The announcement leaked to the wider internet, and routers around the world started sending YouTube traffic to Pakistan instead of to Google. YouTube went dark for much of the world for about two hours, until the bad announcement was withdrawn. It was a mistake, not an attack, but it showed how much the internet depends on BGP announcements being correct.

Deliberate hijacks happen too. An attacker announces someone else's prefixes and diverts their traffic, sometimes to steal data, sometimes to censor it. The defence is a system called RPKI, or Resource Public Key Infrastructure, which lets a network publish a signed record of which AS is allowed to announce which prefixes. Routers that check RPKI can reject announcements that do not match the signed record. Adoption is growing, but it is not yet universal, so BGP security is still an active area of work.

BGP vs OSPF: Different Jobs

BGP and OSPF are both routing protocols, but they do different jobs. OSPF routes inside one organisation. It is fast, detailed, and automatic. BGP routes between organisations. It is slower, policy-driven, and careful. OSPF knows the whole map of its own network. BGP only knows the paths its neighbours have told it about.

Inside a large provider, both run at once. OSPF or IS-IS handles routing inside the provider's own network, and BGP handles routing to the outside world. The border routers run both, and they pass routes between them. This split is the basic shape of internet routing, and it is why the CCNA teaches OSPF in depth and introduces BGP as the protocol that lives beyond the edge.

BGP is not on the CCNA exam in depth, but it is worth understanding, because it explains how the internet actually works. If you know OSPF, you know interior routing. If you know BGP, you know how the whole thing fits together. Our guide on what EIGRP is covers the other interior protocol, and our guide on what NAT is explains the address sharing that happens at the edge of most networks.

Fiber optic internet cables carrying BGP traffic between networks

Internal BGP and External BGP

BGP comes in two forms. External BGP, or eBGP, runs between two different autonomous systems. Internal BGP, or iBGP, runs between routers inside the same autonomous system. They look similar, but they behave differently. eBGP routers must be directly connected, or nearly so, and they change the AS path when they pass a route on. iBGP routers can be far apart, and they do not change the AS path, because the route is still inside the same AS.

iBGP has a quirk that trips up beginners: iBGP routers do not pass on routes they learned from another iBGP router. This is the split-horizon rule, and it prevents loops inside the AS. The result is that every iBGP router must connect to every other iBGP router, in a full mesh, or the routes will not spread. On a large network, that is a lot of connections, so networks use route reflectors, which are routers that are allowed to pass iBGP routes on. It is a detail you will meet if you go deeper into BGP, but for now, the key point is simple: eBGP is between networks, and iBGP is inside one network.

Watch on YouTube: What Is BGP ? | Border Gateway Protocol Explained | BGP Protocol

Should you learn BGP?

If you work for an internet provider, a cloud company, or a large enterprise with its own AS number, yes, BGP is part of your daily work. If you work in a small or medium business, you will probably never configure BGP, because your provider handles it for you. But you should still understand it, because it explains the internet in a way no other protocol does. When a website is unreachable from everywhere, the cause is often a BGP problem, and knowing that saves hours of troubleshooting in the wrong place.

For the CCNA, BGP is a topic to recognise, not to configure. Know what it stands for, know that it routes between autonomous systems, know that it uses TCP port 179, and know that it is a path-vector protocol. That is enough for the exam. If you go on to CCNP, BGP becomes a major topic, and you will learn its path selection, its attributes, and its configuration in depth. By then, the ideas in this article will make that learning much easier.

Frequently Asked Questions

What is BGP in simple terms?

BGP is the protocol that networks use to tell each other which IP addresses they can reach. It is how the internet's thousands of separate networks agree on how to deliver traffic to each other, and it is the reason the internet works as one system.

What is an autonomous system?

An autonomous system is a network under one administration, with its own routing policy. Each one has a unique AS number. Internet providers, large companies, universities, and cloud providers are all autonomous systems.

What is the difference between BGP and OSPF?

OSPF routes inside one organisation, and it is fast and automatic. BGP routes between different organisations, and it is policy-driven and careful. OSPF builds a full map of its own network, while BGP only knows the paths its neighbours announce.

What port does BGP use?

BGP uses TCP port 179. It runs over TCP, which is unusual for a routing protocol, because it needs reliable delivery and it only sends updates when something changes.

What is a BGP hijack?

A BGP hijack is when a network announces prefixes it does not own, and diverts traffic meant for someone else. It can happen by mistake, like the 2008 YouTube incident, or deliberately, to steal or censor traffic. RPKI is the system being built to prevent it.

Conclusion

BGP is the protocol that makes the internet one network instead of thousands of separate ones. Each autonomous system announces the prefixes it can reach, neighbours pass those announcements on, and every network learns how to reach every other network. The AS path keeps it loop-free, and local preference lets each network express its own business choices.

It is slower and more careful than OSPF, because it has to be. It carries the trust of the whole internet in its announcements, and when that trust is broken, the whole world notices. Learn the basics, and you will understand how the internet actually works.

Related articles:

What Is OSPF? How Open Shortest Path First Works

The routing protocol for inside one network, and how it differs from BGP.

What Is EIGRP? How It Works and EIGRP vs OSPF

Cisco's fast-converging routing protocol, and how it compares with OSPF.

What Is NAT? Network Address Translation Explained

How NAT lets many devices share one public address, and why it exists.

Want a clear price for your project?

Tell us what you need and we will send a free quote with no hidden charges.

Get a Free Quote