It loses two electron in its 4s subshell to achieve stability and forms ion ##Ca^(2+)##.

##Ca^(2+)## = 1##s^2##2##s^2##2##p^6##3##s^2##3##p^6##

N ( Z=7) on the other hand has seven electrons and wants to gain three electrons to achieve stable noble gas configuration.Nitrogen atom on gaining three electrons forms negative nitride ion, ##N^(3-)## ion.

N ( Z=7) = 1##s^2##2##s^2##2##p^3##

##N^-3## = 1##s^2##2##s^2##2##p^6##

Two Nitrogen atoms gains three electrons each ( total of six) from three Ca atoms, each Ca atom loses two electrons (total of six) to two Nitrogen atom , in this process each Ca atom becomes ##Ca^(2+)## ion and nitrogen atom after gaining three electrons becomes ##N^(3-)## ion.

so in all we have three ##Ca^(2+)## ions and two nitride ##N^(3-)## ions.
so the formula becomes ##Ca_3N_2##.