Codoping of p-type GaN nanowires with Mg and oxygen was investigated using first-principles calculations. The Mg becomes a deep acceptor in GaN nanowires with high ionization energy due to the quantum confinement. The ionization energy of Mg doped GaN nanowires containing passivated Mg-O complex decreases with increasing the diameter, and reduces to 300 meV as the diameter of the GaN nanowire is larger than 2.01 nm, which indicates that Mg-O codoping is suitable for achieving p-type GaN nanowires with larger diameters. The codoping method to reduce the ionization energy can be effectively used in other semiconductor nanostructures. (C) 2010 American Institute of Physics.