Knowledge of the composition of the Earth's core1,2,3 is important for understanding its melting point and therefore the temperature at the inner-core boundary and the temperature profile of the core and mantle. In addition, the partitioning of light elements between solid and liquid, as the outer core freezes at the inner-core boundary, is believed to drive compositional convection4, which in turn generates the Earth's magnetic field. It is generally accepted that the liquid outer core and the solid inner core consist mainly of iron1. The outer core, however, is also thought to contain a significant fraction of light elements, because its density—as deduced from seismological data and other measurements—is 6–10 per cent less than that estimated for pure liquid iron1,2,3. Similar evidence indicates a smaller but still appreciable fraction of light elements in the inner core5,6. The leading candidates for the light elements present in the core are sulphur, oxygen and silicon3. Here we obtain a constraint on core composition derived from ab initio calculation of the chemical potentials of light elements dissolved in solid and liquid iron. We present results for the case of sulphur, which provide strong evidence against the proposal that the outer core is close to being a binary iron–sulphur mixture7.