A source host will compare the destination address to that of its own network. If it is on the same network, it will use something like ARP to resolve the layer-3 (e.g. IP) address to the layer-2 (e.g. MAC) address. Then, it will encapsulate the layer-3 packet with a layer-2 frame and send it directly to the local destination host.
If the destination address is on a different network. The host will use the layer-2 address of its configured gateway (the host on the network that knows how to reach other networks; usually a router) to encapsulate the layer-3 packets with a layer-2 frame. The host may need to use something like ARP to resolve the gateway layer-3 address to a layer-2 address.
A router will strip off the layer-2 frame, look at the layer-3 destination address, look in its routing table to see if it has a route to the destination network. If it has no route, it will drop the packet. If it has a route, it will create a layer-2 frame for the interface to which it must send the packet to reach the destination, and it forward the new frame out the interface toward the destination.