This work is focused on obtaining a general function for calculating the mass attenuation coefficients of samples whose compositions are known such as waste, biota or NORM (Naturally Occurring Radioactive Materials) samples. After determining the general function, it is possible to assess the self-absorption effects by the self-absorption correction factor, which is really important to consider for samples measured by gamma spectrometry. In order to obtain a general function of the mass attenuation coefficients dependent on the gamma emission energy (Eγ) and the chemical elements (Zi) with their respective concentrations (xi), it was necessary to fit the tabulated values of the mass attenuation coefficients versus gamma energy in the range of 20 keV–2000 keV for each chemical element. This is the energy range for the majority of gamma emissions of natural radionuclides. Once those fittings for each chemical element, Z, from 1 (H) to 92 (U) were done, the parameters, that resulted from those fittings, were fitted versus the atomic number, Z. This provides a general function that allows to calculate the mass attenuation coefficient by knowing the gamma emission energy and the sample composition. Finally, both the general function for calculating the mass attenuation coefficient and the self-absorption correction factor, which is used in gamma spectrometry with coaxial Ge detectors, were validated by comparisons made with the values provided by databases for several samples with widely different known densities, compositions and activity concentrations.