We study analytically the non-Markovianity of a spin ensemble, with arbitrary number of spins and spin quantum number, undergoing a pure dephasing dynamics. The system is considered as a part of a larger spin ensemble of any geometry with pairwise interactions. We derive exact formulas for the reduced dynamics of the system and for its non-Markovianity as assessed by the witness of Lorenzo et al. [Phys. Rev. A 88, 020102(R) (2013)]. The non-Markovianity is further investigated in the thermodynamic limit when the environment's size goes to infinity. In this limit and for finite-size systems, we find that the Markovian character of the system's dynamics crucially depends on the range of the interactions. We also show that when the system and its environment are initially in a product state, the appearance of non-Markovianity is independent of the entanglement generation between the system and its environment.