Nitride-based device structures for electronic and optoelectronic applications usually incorporate layers of Al x Ga 1-x N, and n-and p-type doping of these alloys is typically required. Experimental results indicate that doping efficiencies in Al x Ga 1-x N are lower than in GaN. We address the cause of these doping difficulties, based on results from first-principles densityfunctional-pseudopotential calculations. For n-type doping we will discuss doping with oxygen, the most common unintentional donor, and with silicon. For oxygen, a DX transition occurs which converts the shallow donor into a negatively charged deep level. We present experimental evidence that oxygen is a DX center in Al x Ga 1-x N for x>~0.3. For p-type doping, we find that compensation by nitrogen vacancies becomes increasingly important as the Al content is increased. We also find that the ionization energy of the Mg acceptor increases with alloy composition x. To address the limitations on p-type doping we have performed a comprehensive investigation of alternative acceptor impurities; none of the candidates exhibits characteristics that surpass those of Mg in all respects.