A new semiempirical atomic mass formula is presented. Special emphasis has been put on a theoretical basis for the microscopic ( shell-correction ) part, which is added to the macroscopic droplet-model expression. The latter includes the response to the surface diffuseness. The shell function, which is simple and analytic, is derived by bunching the average single-particle spectrum of nuclei with correct size according to the magic numbers. Shell effects from the inner shells are taken care of. In addition, ideas of changing magicities along neutron ( proton ) magic isotone ( isotope ) chains, and of damping of the off-Fermi-energy-shell contributions are introduced. These may be important for reliable extrapolations to very neutron-rich ( or neutron-deficient ) regions of the nuclear chart.