Thunderclouds are electrified when charge is transferred between small and large ice particles colliding in a cloud that contains strong updrafts. The small ice particles rise with one type of charge and the large ice particles fall and carry with them downward the other type of charge, which is most often negative, so that normally lightning lowers negative charge from cloud to the ground. While the mechanism of ice charging is well established, the nature of the charge transfer between the colliding ice particles is not very well understood on the atomic level, and no present theory can explain fully the charge transfer, or even the sign of the charging. Here we propose a new charge separation mechanism that is based on molecular simulations of the collisions, keeping track of the individual charges as they move in the form of salt ions from one ice particle to another. Under normal conditions, when sulfates dominate as cloud condensation nuclei, this ionic mechanism is consistent with the prevailing negative lightning in thunderclouds. Moreover, with dearth of sulfate anions, the present mechanism predicts a shift towards positive charging. This fits well to a large range of observations of enhanced positive lightning, connected with smoke rich in chlorides and nitrates, that could not be explained satisfactorily previously.