Despite its ubiquity in the global internet, Border Gateway Protocol can be a complicated protocol to understand.
BGP can be used as an internal routing protocol, like Open Shortest Path First or Enhanced Interior Gateway Routing Protocol, but its primary function is to direct how packets should be forwarded throughout the global internet. This is called external BGP.
Thousands of entities -- like internet service providers, government departments and educational organizations -- own and operate their own internal networks, which are registered as unique autonomous systems (ASes). Each AS has its own identifying AS number, which BGP routers use to route and exchange traffic. These ASes make up the global internet.
It is the job of BGP routers to forward traffic between these ASes. To do this, BGP routers evaluate a packet's prefix information to assess path attributes, such as origin, next hop, local preference and AS path. The BGP router uses this routing information to select the packet's route to its destination.
External BGP requires peering agreements that enable BGP routers to establish direct connections with neighboring ASes. Building a peering agreement is a manual process in which network pros configure permissions, authentication and policies.
Watch this animated video to learn more about the basics of how BGP works.