Abstract Given a ring R and one of its proper ideals S , we obtain a compactification of the prime spectrum of S through a mainly algebraic process. We call it the R -nilcompactification of $$\textrm{Spec}S$$ <mml:math xmlns:mml="http://www.w3.org/1998/Math/MathML"> <mml:mrow> <mml:mtext>Spec</mml:mtext> <mml:mi>S</mml:mi> </mml:mrow> </mml:math> . We study some categorical properties of this construction.