At the level of nuclear dimensions mass is not a conserved quantity , but one derived from the four vectors of special relativity.
In special relativity each particle and composite of particles is described by a four vector. The energy momentum vector
$$\vec p=\pmatrix{E \\ p_xc \\ p_y c \\ p_z c}=\pmatrix{E \\ \vec p c}$$
has as a length the invariant mass, $m_0$:
$$\sqrt{P\cdot P}=\sqrt{E^2-(pc)^2}=m_0c^2$$
The four vectors of protons and neutrons that make up the nucleus sum up to a single four vector,which has the invariant mass of the single nucleus. The summing up is vectorial. It is only energy and momentum that are conserved, not mass.
The difference in mass between the sum of free nucleons and the mass of the nucleus is similar to the difference in length when one adds two vectors at an angle, the new vector length is less than the sum of the two lengths.