The first-principles method and the evolutionary algorithm are used to identify stable high pressure phases of potassium azide (KN3). It has been verified that the stable phase with space group I4/mcm below 22 GPa, which is consistent with the experimental result, will transform into the C2/m phase with pressure increasing. These two phases are insulator with anions. A metallic phase with P6/mmm symmetry is preferred above 40 GPa, and the N atoms in this structure form six-membered rings which are important for understanding the pressure effect on anions and phase transitions of KN3. Above the studied pressure (100 GPa), a polymerization of N6 rings may be obtained as the result of the increasing compactness.