The network layer (also called layer3) manages device addressing tracks the location of devices on the network and determines the best way to move data. Which means that the network layer must transport traffic between devices that aren't locally attached. Routers are specified at the network layer and provide the routing service switch an internetwork.
It happens like this first when a packet is received on a router interface the destination IP address is checked. If the packet is not destined for that particular router. It will look up the destination network address in the routing table. Once the router chosen an exit interface the packet will be sent to that interface to be framed and sent out on the local network. If the router cannot find an entry for the packets destination network in the routing table the packets destination network in the routing table the router drops the packets.