If a spell you cast has {X} in its mana cost, you choose the value of X before calculating the spell's total cost. For example, if that spell's mana cost is {X}{R}{G} and you've chosen red and green, you could choose 5 as the value of X and pay {3}{R}{G} to cast the spell.