  High pressure synthesis of rhenium nitride pernitride ReN$_2$ with crystal
structure unusual for transition metal dinitrides and high values of hardness
and bulk modulus attracted significant attention to this system. We investigate
the thermodynamic and electronic properties of the P2$_1$/c phase of ReN$_2$
and compare them with two other polytypes, C2/m and P4/mbm phases suggested in
the literature. Our calculations of the formation enthalpy at zero temperature
show that the former phase is the most stable of the three up to pressure p=170
GPa, followed by the stabilization of the P4/mbm phase at higher pressure. The
theoretical prediction is confirmed by diamond anvil cell synthesis of the
P4/mbm ReN$_2$ at $\approx$175 GPa. Considering the effects of finite
temperature in the quasi-harmonic approximation at p=100 GPa we demonstrate
that the P2$_1$/c phase has the lowest free energy of formation at least up to
1000 K. Our analysis of the pressure dependence of the electronic structure of
the rhenium nitride pernitride shows a presence of two electronic topological
transitions around 18 GPa, when the Fermi surface changes its topology due to
an appearance of a new electron pocket at the high-symmetry Y$_2$ point of the
Brillouin zone while the disruption of a neck takes place slightly off from the
$\Gamma$-A line.
