The primary purpose of the actual routing function of a router is to provide connections between different subnets. Most routers also incorporate an Ethernet switch that provides connection between different devices on the same subnet.
When a computer needs to contact another computer it compares the target address with its own address to work out if they are both on the same subnet. If they are, then it sends the packet over its Ethernet connection with the local target address. The switch in the router recognises the target is on another of its Ethernet connections and sends the packet straight to the target.
However, if the packet is destined for a different subnet, it sends the packet specifically to the router (its gateway) with details of the target address. The router will pass this on to another network (for a home router this will be the Internet). The router may have to use another gateway if the target is not on a subnet that the router is directly connected to. This can continue through many routers before the final destination (target) is reached.
I hope this helps.
The router assigns independent addresses for each device connected ( separate from the address you ISP assigns to you )…..these addresses are unique…..so when a request comes from that device ….whatever the request maybe…the router knows what device sent that request and where to send the info to….
This is a very simplified explanation……