Border Gateway Protocol (BGP) is the standard protocol that autonomous systems (AS) on the internet use to exchange routing information and to decide the optimal routes for delivering data packets from within to their destinations.
The internet is a network of networks. Individual networks, such as the ones controlled by big tech companies, academic organisations, governments or ISPs, are known as autonomous systems. These systems contain the routing information for how to reach the connected devices. ASs advertise their routing information to their neighbours through TCP/IP connections. Each AS gets routing information from its immediate neighbours and propagates it further on the internet. Every AS has an ASN number, which can be obtained directly from IANA or from its parent organisation.
Routes are exchanged and traffic is transmitted through external BGP on the internet. ASs can also use optional internal BGPs to route traffic through their internal networks.
A good analogy for BGP is the postal service. Each branch of the Post Office knows the next destinations the parcels should be sent to, and can decide which partner carrier to use for international post. Once parcels have reached the sorting office at the destination - after going through customs checks, possibly via different transportation methods - they are ready to be delivered to the recipients through the most efficient routes by delivery drivers.
BGP routing advertising is based on trust, and ASs implicitly trust their neighbours. There have been occasions where unreachable routing information was falsely advertised - either deliberately or accidentally - resulting in fraud and popular services becoming unavailable.