The variations in the electronic properties of the two-dimensional electron gas (2DEG) in AlxGa1-xN/GaN heterostructures due to an AlN embedded spacer layer were investigated by using Shubnikov–de Haas (SdH) measurements. The carrier densities of the 2DEGs in the Al0.4Ga0.6N/AlN/GaN and the Al0.4Ga0.6N/GaN heterostructures, determined from the SdH data, were 8.75×1012 and 8.66×1012 cm-2, respectively. The electron carrier density and the mobility of the 2DEG in the AlxGa1-xN/GaN heterostructure with an AlN spacer layer were larger than those in the AlxGa1-xN/GaN heterostructure. The electronic subband energies, the wave functions, and the Fermi energies in the Al0.4Ga0.6N/AlN/GaN and Al0.4Ga0.6N/GaN heterostructures were calculated by using a self-consistent method taking into account spontaneous and piezoelectric polarizations. These present results indicate that the electronic parameters of the 2DEG occupying an AlxGa1-xN/GaN heterostructure are significantly affected by an AlN spacer layer, and they can help to improve the understanding of the - applications of AlxGa1-xN/GaN heterostructures with AlN spacer layers in high-speed and high-power electronic devices.