You must live in Norway at least half of the time you have a residence permit for. If you have been given a residence permit for one year, you cannot stay abroad for more than six months in total during that year. If you have been given a residence permit for several years, you cannot stay abroad for more than a total of 182 days in any 365 day period. If you do so, you can lose your residence permit, and you will have to apply for a new residence permit.
If you are later going to apply for a permanent residence permit, you can normally not have stayed outside Norway for more than a total of seven months in the past three years.