Electrified aerosols have been observed in the lower troposphere and in the mesosphere, but have never been detected in the stratosphere and upper troposphere. We present measurements of aerosols during a balloon flight to an altitude of ~24 km. The measurements were performed with an improved version of the STAC aerosol counter dedicated to the search for charged aerosols. It is found that most of the aerosols are charged in the upper troposphere for altitudes below 10 km and in the stratosphere for altitudes above 20 km. On the contrary, the aerosols seem to be uncharged between 10 km and 20 km. Model calculations are used to quantify the electrification of the aerosols with a stratospheric aerosol-ion model. The percentages of charged aerosols obtained with model calculations are in excellent agreement with the observations below 10 km and above 20 km. On the other hand, the model cannot reproduce the absence of detected electrification in the lower stratosphere, such that a distinct unknown process in this altitude range inhibits electrification. The presence of sporadic transient layers of electrified aerosol in the upper troposphere and in the stratosphere could have significant implications for sprite formation.