Regardless of which protocol is in use, the premise is the same: the path chosen is the one with the smallest metric. Admittedly, I've oversimplified this, but I wanted to give you an overview before moving on.
All routing devices hold a routing table that contains information about the networks, interfaces, and metrics. Even your Windows PC will have a routing table. And that is where I'm going to start.