Demons and devils were once like you and me, but an eternity in Hell has changed them. Not just physically, but mentally. Do not try to summon demons and devils. Do not try to understand them. But most of all, never ever make a pact with them. You always end up dead, your soul forever cursed to replenish the infernal armies of Hell.Most people equate the act of summoning a devil or demon with powerful mages and spells like Gate or Planar ally. While this is certainly true, it is also true that many besides powerful mages and clerics can attempt to summon the extra-planar creatures.
The details of how and why are sketchy at best and not always accessible to everyone, as the information is jealously guarded by sages, cultists, warlocks, witches, sorcerers, shamans and the like.
Usually the act involves a summoning symbol of some kind (such as a pentagram), a lot of salt, a number of black candles, a handful or two of rare herbs and incenses, some invocations spoken in infernal/abyssal, quite a lot of death and the true name of the devil/demon. Also worth noting that certain items can further facilitate the success of the ritual. Especially a sacrificial dagger made of silver/bone/cold iron and/or a sacrificial dagger made of bone can help a lot.
But there are exceptions of course. For example, it is said that a box containing certain items (picture of you, graveyard dirt and a bone from a black cat amongst others) buried in the middle of a dirt crossroad at midnight will summon a demon with the intent purpose of striking a pact regarding your soul.