We present a quantitative study of the role played by different components characterizing the nucleon–nucleon interaction in the evolution of the nuclear shell structure. It is based on the spin–tensor decomposition of an effective two-body shell-model interaction and the subsequent study of effective single-particle energy variations in a series of isotopes or isotones. The technique allows to separate unambiguously contributions of the central, vector and tensor components of the realistic effective interaction. We show that while the global variation of the single-particle energies is due to the central component of the effective interaction, the characteristic behavior of spin–orbit partners, noticed recently, is mainly due to its tensor part. Based on the analysis of a well-fitted realistic interaction in the sdpf shell-model space, we analyze in detail the role played by the different terms in the formation and/or disappearance of N=16, N=20 and N=28 shell gaps in neutron-rich nuclei.