A router is a device that forwards data packets between computer networks, creating an overlay inter network. A router is connected to two or more data lines from different networks. When a data packet comes in on one of the lines, the router reads the address information in the packet to determine its ultimate destination. Then, using information in its routing table or routing policy, it directs the packet to the next network on its journey.
In the Below link you can see an animation on How the Router works?