Hydrogen is an important light element in the Earth’s core for its high cosmochemical abundance and strong affinity to iron under core-formation conditions. Thus, constraining the core composition requires knowledge on the distribution of hydrogen between the liquid outer core and solid inner core. Here we investigate the chemical equilibrium of hydrogen at the inner-core boundary by calculating the chemical potential of hydrogen in solid and liquid iron-hydrogen alloys, respectively, using first-principles molecular dynamic simulations and neural network methods. We find that hydrogen partitions preferentially into the outer core and provides a major contribution to the density jump across the inner-core boundary. Combining geophysical constraints, mineral physics data, and chemical equilibrium, we evaluated light element abundances in the outer and inner cores simultaneously. Our results suggest hydrogen and silicon are the preferred light elements in the core, implying a relatively reduced environment during the Earth’s accretion and core-formation processes.