Introduction
The Internet is used daily, but how is data routed across the globe? The Border Gateway Protocol (BGP) is the protocol that connects different ISPs and enables global IP reachability.

What is BGP?
BGP stands for Border Gateway Protocol. It runs between autonomous systems (AS), which are collections of networks under a single administrative domain and routing policy. The global Internet is composed of many such autonomous systems that interconnect to form a large routing topology.

BGP's primary function
BGP's main task is to exchange routing information between different ASes. Each AS advertises the IP prefixes it can reach along with the AS path to those prefixes. BGP peers establish sessions to share and receive these route advertisements so each AS learns how to reach networks operated by others.

Path selection and routing
When multiple routes to the same destination exist, BGP selects the preferred path using a route selection algorithm that considers several attributes. Common factors include AS path length, local routing policies, and the chosen exit point for the prefix. Shorter AS-paths are often preferred, but operator policies can override length-based preference.

How data is forwarded
Once a border router learns the best path to a prefix, it installs the route in the local routing table. When a packet arrives with a destination in that prefix, the router consults the routing table and forwards the packet to the selected next hop or exit point so the packet can traverse the network along the chosen path to its destination.
Summary
BGP enables ISPs and autonomous systems to exchange reachability information and to select preferred routes based on path attributes and policies. Through BGP peering and route propagation, IP packets can be routed across multiple administrative domains to reach destinations anywhere on the global Internet.