As described by Brian, it starts with domestic laws in terms of determining who is a resident for tax purposes. Then you look to the treaty rule, which sets out a general rule on where you are resident. It is possible that you could be found resident in two different jurisdictions, and for that the treaty has a tie-breaker rule that has a number of different steps to take in breaking that tie.
The first one you would look to is where you have a permanent home available to you. Very often that is where the tie is broken. If it's not broken there, it then looks to your economic and social ties to determine where there are closer ties between the two jurisdictions, and then it cascades to a couple more criteria if you can't break the tie with either of the first two. It ensures that you're only getting benefits under the treaty in respect of being resident in one jurisdiction and not in both.