A router forwards data packets between computer networks based on IP addresses. It examines header information in each packet and determines the best path to send it towards its destination, choosing the route with the lowest cost. Routers work at the IP protocol level and maintain routing tables with information about neighboring routers and the costs of routes to efficiently transmit data packets between networks.