For individuals, very generally it's where you have the closest connections. There are “deemed” rules where if you spend so many days in Canada you may be treated as a resident, or if you're a member of the diplomatic corps you may be deemed to be a Canadian resident. Apart from that, it's all factually based.
Colloquially, sometimes it's where you hang your hat, where you have your driver's licence, your club memberships, where you own your home, and other factors such as those.