The rare-earth metals have high magnetic moments and a diverse range of mag
netic structures(1). Their magnetic properties are determined by the occupa
ncy of the strongly localized 4f electronic shells, while the outer 5-d ele
ctrons determine the bonding and other electronic properties(2). Most of th
e rare-earth atoms are divalent, but generally become trivalent in the meta
llic state, In some materials, the energy difference between these valence
states is small and, by changing some external parameter (such as pressure)
, a transition from one to the other occurs. But the mechanism underlying t
his transition and the reason for the differing valence states are not well
understood. Here we report first-principles electronic-structure calculati
ons that enable us to determine both the valency and the lattice size as a
function of atomic number, and hence understand the valence transitions. We
iind that there are two types of f electrons: localized core-like f electr
ons that determine the valency, and delocalized band-like f electrons that
are formed through hybridization with the s-d bands and which participate i
n bonding. The latter are found only in the trivalent systems; if their num
ber exceeds a certain threshold, it becomes energetically favourable for th
ese electrons to localize, causing a transition to a divalent ground state.