When casting a spell with X in the mana cost, X will equal what was chosen when the spell was cast. (Usually this means that this was what was mana paid for as well, but effects that raise or lower costs can alter this.) For example, if you cast a Fireball targeting a Stampeding Rhino, in order to deal lethal damage to the Rhino the value of X would have to be four. The total converted mana cost of this spell on the stack will be five, as you have to pay one red mana as well. In other words, when on the stack the value of X is whatever its controller chosen when playing the spell.
When in any other zone (library, hand, graveyard etc.) the value of X equals zero. This matters for effects that look at or use the converted mana cost of a card. For example, if a Fireball is revealed when resolving the triggered ability of a Dark Tutelage, the controller of this ability will lose just one life as the value of X in this instance is zero.