BGP is used to exchange routing and reachability information between autonomous systems (AS). It works by allowing routers running BGP to establish peering sessions with neighboring routers in other ASes to exchange routing information. BGP uses path vector routing to exchange information about available routes and determines the best paths between any two points on a network using attributes like local preference, AS path length, origin type and more. BGP configuration involves enabling BGP on interfaces, establishing BGP neighbor relationships, redistributing routes into BGP, and controlling the best path selection process.