Look at the top two cards of your library. Put one of them into your hand and the other into your graveyard.
Madness {1}{U} (If you discard this card, discard it into exile. When you do, cast it for its madness cost or put it into your graveyard.)
A spell cast for its madness cost is put onto the stack like any other spell. It can be countered, copied, and so on. As it resolves, it’s put onto the battlefield if it’s a permanent card or into its owner’s graveyard if it’s an instant or sorcery card.
Cards are discarded in a Magic game only from a player’s hand. Effects that put cards from a player’s library into that player’s graveyard do not cause those cards to be discarded.
Casting a spell for its madness cost doesn’t change its mana cost or its converted mana cost. You just pay the madness cost instead.
Effects that cause you to pay more or less for a spell will cause you to pay that much more or less for its madness cost, too.
If there is only one card left in your library, you’ll put it into your hand. You won’t lose the game for having zero cards in your library until you’re required to draw a card.
If you choose not to cast a card with madness when the madness triggered ability resolves, it’s put into your graveyard. You don’t get another chance to cast it later.
If you discard a card with madness to pay the cost of a spell or activated ability, that card’s madness trigger (and the spell that card becomes, if you choose to cast it) will resolve before the spell or ability the discard paid for.
If you discard a card with madness while resolving a spell or ability, it moves immediately to exile. Continue resolving that spell or ability—the card is not in your graveyard at this time. Its madness trigger will be placed onto the stack once that spell or ability has completely resolved.
Madness works independently of why you’re discarding the card. You could discard it to pay a cost, because a spell or ability tells you to, or even because you have too many cards in your hand at the end of your turn. You can’t discard a card with madness just because you want to, though.
When you cast a card with madness, it was still discarded. If it was discarded to pay a cost, that cost is still paid. Abilities that trigger when a card is discarded will still trigger.