The number are conserved but the total mass is nor conserved.
The total mass of the free protons/neutrons is more than their total mass within the nucleus. The lost mass (= Δm), gets converted into energy as per the relation. E = (Δ m)c2
[Also, accept alternative ways of explaining the phenomenon]