So, How does a router work?
The router connects a network and networked devices. In the case of a home or small business network, this will probably be an internet connection and some computers.
Every time the router receives traffic, it inspects the header to decide where to send it. If it's an incoming packet, it looks at the destination address and checks to see if the computer with that address is connected to it. It then finds which port the computer is attached to and sends the packet through that port. If that address isn't attached to the router, it will either send it to any other routers attached to it, or return the packet to the computer that sent it. If it has to return a packet to the sender, you might see an "address not found" message. This is from the destination router, which told your router or PC that it can't find the IP address you wanted.
To decide if the address is connected to it, the router consults its routing table. This is a table in the software which tells the router which computer IP addresses are connected to which port. That's how it knows where to send the packet.
If a computer on your network sends traffic to the router, it does exactly the same thing, except in the home network there are only two destinations to send the traffic. These will be the first and second choice enterprise routers of the ISP. They then do the routing on a much larger scale, but using exactly the same principles.
For example, say a packet arrives from the internet for IP address 192.168.101.1. The router holds the packet and looks in its routing table to see if it has a computer connected to it with that address. If a computer exists with that address, it checks the table to see which port it's connected to, then forwards that packet to the destination through that port. On most modern routers, this whole process takes less than a second.
It does this for every single packet that it transmits or receives to ensure traffic goes to the correct destination.