Legal residence for at least 4 years
In order to be granted a permanent residence permit, you must have been a
legal resident of Denmark for at least the past four years, and you must have held a residence permit issued under the
Danish Aliens Act, sections 7-9e (family reunification, asylum, studies, work, etc.) for your entire period of residence.
If you hold a residence permit under the Danish Aliens Act, section 9f (religious workers), you can be granted a a permanent residence permit if you meet the normal requirements - including legal residence for at least four years - and have formed a strong attachment to Denmark.
The first paragraph of the letter granting you a residence permit or an extension of a residence permit states which section of the Danish Aliens Act it was issued according to.
One or more grounds for residence permit
You will meet the requirement by having held a residence permit on the same grounds for the entire four-year period, for example, as an employee.
You can also meet the reguirement by having held several residence permits on different grounds during the four-year period, for example, as a student first, then as an employee, or as an au pair first, then as a family reunified person.
The requirement is that you have been a legal resident of Denmark for at least the past four years. An exception to this rule, however, is if you have a held residence permits on the grounds of several marriages/registered partnerships/cohabiting partnerships. In this situation you will only meet the requirement when you have held a residence permit for at least four years on the grounds of your latest marriage/partnership. If you get divorced and subsequently re-marry (or enter into a new registered partnership/cohabiting partnership), the four years will be counted anew.