The polarity of GaN epilayers grown by molecular beam epitaxy is controlled using Mg. This is achieved by simultaneously exposing the surface to Mg and NH3 fluxes during growth interruption. Reflection high-energy electron diffraction (RHEED) indicates the formation of a Mg3N2, layer. Overgrowing GaN on this surface leads to a polarity inversion either from Ga to N or N to Ga. The change of the polarity is followed in situ by RHEED via surface reconstructions of the GaN surface. The polarity inversion is further confirmed by convergent beam electron diffraction experiments. Finally, high-resolution transmission electron microscopy images show different interface morphologies between Ga/N and N/Ga polarity boundaries. The control of the GaN polarity opens the way for novel periodic polarity structures dedicated to non-linear optics. (C) 2002 Elsevier Science B.V. All rights reserved.