The two-dimensional electron gas (2DEG) observed at the interface between LaAlO3 (LAO) and SrTiO3 (STO) is known to be very sensitive to the proximity of the LaAlO3 surface and the conditions to which the surface is exposed. We use first-principles calculations to study surface reconstructions on LAO films, taking into account that the LAO surface can be charged. The results for the charged surfaces and for the coupling between the surface and the 2DEG enable us to account not only for the behavior of the 2DEG as a function of thickness of the LAO layer, but simultaneously determine the stable terminations and reconstructions on the LAO surface under a variety of conditions. Our studies of charged surfaces are based on an extension of the methodology of Lozovoi et al. [J. Chem. Phys. 115, 1661(2001]. From the calculated electronic structure of the unreconstructed (but relaxed) AlO2 and LaO surface terminations of LAO, we find surface states having excess holes (AlO2 termination) or excess electrons (LaO termination). This result is central to understanding the mechanism of 2DEG formation, and is consistent with a 2DEG of density 3.3×10 14 cm −2 being intrinsic to the LaO-TiO2 interface in the LAO/STO system. We explore the effects of the Al-adatom, O-vacancy and H-adatom surface reconstructions on the 2DEG density, and find that the stability of different reconstructions is tied to the thickness of the LAO layer as well as the surface exposure conditions. We find that including the effects of charging of the surface significantly stabilizes the AlO2 termination versus the LaO termination. Overall, our methodology has the advantage of decoupling first-principles calculations for the interface from those for the charged surface, and constitutes a general approach that can be applied to the commonly occurring problem of charge exchange between the surface and the interface of a thin film with a substrate, or between the surface and defects/impurities in the bulk of a material.