Routers determine the best path for data packets to travel between networks. They maintain routing tables that contain the destination address, cost of the path, and next hop to forward each packet. Routing protocols allow routers to share information and dynamically update their tables to route around failures and choose the lowest cost path. This allows packets to be properly forwarded from any source to destination on the internet through a system of destination-based connectionless forwarding.