  Shell effects in atomic nuclei are a quantum mechanical manifestation of the
single--particle motion of the nucleons. They are directly related to the
structure and fluctuations of the single--particle spectrum. Our understanding
of these fluctuations and of their connections with the regular or chaotic
nature of the nucleonic motion has greatly increased in the last decades. In
the first part of these lectures these advances, based on random matrix
theories and semiclassical methods, are briefly reviewed. Their consequences on
the thermodynamic properties of Fermi gases and, in particular, on the masses
of atomic nuclei are then presented. The structure and importance of shell
effects in the nuclear masses with regular and chaotic nucleonic motion are
analyzed theoretically, and the results are compared to experimental data. We
clearly display experimental evidence of both types of motion
