When casting a spell, the very first thing that happens is the card representing the spell will leave the zone that it is currently in and go on the stack. Often the exact order that things happen does not matter, but for some spells, the fact that this card is now on the stack will matter.
For example, when playing Molten Psyche, it will leave your hand and go on the stack right away. This means that it is not in your hand when it resolves, and it will not be shuffled into your library.
Another example where this matters would be if you controlled Adamaro, First to Desire. If your opponent has four cards in hand, he can play Lightning Bolt and end up dealing lethal damage to Adamaro. This is because as soon as he plays the Lightning Bolt, the power and toughness of Adamaro will go to three.
While most spells are cast from your hand, this concept also applies when casting spells from somewhere unusual, such as the graveyard using flashback. If you announce that you’re casting Unburial Rites with flashback, it’s too late for the opponent to cast Purify the Grave to stop it from being played, because that card is already on the stack–and no longer in the graveyard–before anybody has a chance to respond.