Altars can be quite mysterious to a beginning player. Yet, they are very important for finishing the game. Here follows the most important information on altars in NetHack.
Altars can occur anywhere in the main dungeon, sometimes even more than one on a level.
See the quest.map file for more information on these. The effect of your actions depends not only on your luck and your current standings with your god, but most of all on the altar's alignment, compared to your own. Every altar has an alignment, which determines to what god it belongs. The alignment of randomly generated altars is, as expected, random, and so is the altar in the Mines' Town. The altars in Gehennom are unaligned, since they all belong to Moloch, the renegade god.