Library

The library is one of the six main zones in Magic: the Gathering.

Description
The library is the pile from which you draw cards, either the opening hand at the beginning of the game, during your draw phase, or because of an effect of a spell or ability. Cards drawn are put into a player's hand, from which they can be played. Some effects return cards to the top or bottom of your library, or cause cards to be shuffled into your library. Other effects allow you to search your library for a card; these effects can be referred to as "tutors".

Typically, whenever a player has looked through the contents of their library, that player shuffles the library before resuming play. This is to preserve the random order of the cards to be drawn, and allow for luck to play a part in the game. In organized play, many judge policies concern preserving the randomness of the library when a player illicitly obtains knowledge of the order of a player's library.

The library also serves as an alternative win condition by being a finite resource. Once all of the cards in a library are drawn or otherwise removed, a player will lose the game if an effect causes him or her to draw a card. While most decks try to win by reducing life points, some aim at reducing another player's library to zero cards.

Flavor
Flavorfully speaking, the library represents a subset of all the spells the player (who is a planeswalker), knows. It is a subset because the player's entire Magic collection would be all the spells and lands he has encountered and learned in history.

Rulings

 * If player puts two or more cards on the top or bottom of another player's library (as with Misinformation), that player may arrange them in any order (unless otherwise specified) and doesn't reveal this order to the owner of the library.

Putting cards on top of a library
Putting cards on top of a library is primary in blue.

Putting cards nth from the top of a library
The delaying mechanic of putting cards nth from the top of a library is primary in white (e.g. Approach of the Second Sun)

Playing cards off top of library, at a cost
Playing cards off top of library, at a cost, is primary in blue, secondary in green. This effect is usually on a permanent that makes the top of your library be played face-up. You may then cast cards off the top of your library. Green, when it does this effect, usually limits you to playing a subset of permanents.

Playing cards off top of library, for free
Playing cards off top of library for free used to be in blue, but is now primary in red. This is because it has a chaotic feel (you don't know what's about to happen).

Restocking
Putting cards from your graveyard back into your library ("Restocking") is primary in green and secondary in blue. Green does it most as a "cycle of life" flavor, but blue does it on occasion, sometimes also shuffling your hand in as well and then drawing you cards.

Constructed (Including standard, historic, pioneer, modern and vintage)
Libraries in this format have a minimum of 60 cards, and no maximum (note that players playing paper Magic should keep their decks small enough so that they can shuffle it in two hands). A library and its sideboard together may not contain four or more copies of a same card unless otherwise specified, even if they are printed in different sets.

Limited (Including draft, sealed and cube)
Libraries in this format have a minimum of 40 cards.

Commander/Singleton
100 cards exactly. A library and its sideboard together may not contain two or more copies of a same card, even if they are printed in different sets. In a commander deck, one of a legendary creature (or planeswalker if written) in the mainboard is your commander.

Brawl
A sixty-card commander library.

Starting Library
The Mystery Booster test card Witty Demon introduced the concept of a "Starting library". This should be interpreted as "starting deck," including cards that started the game in a zone other than your library (such as Buried Ogre or Memory Bank).