The concept of available energy of a collisionless plasma is discussed in the context of magnetic confinement. The available energy quantifies how much of the plasma energy can be converted into fluctuations (including nonlinear ones) and is thus a measure of plasma stability, which can be used to derive linear and nonlinear stability criteria without solving an eigenvalue problem. In a magnetically confined plasma, the available energy is determined by the density and temperature profiles as well as the magnetic geometry. It also depends on what constraints limit the possible forms of plasma motion, such as the conservation of adiabatic invariants and the requirement that the transport be ambipolar. A general method based on Lagrange multipliers is devised to incorporate such constraints in the calculation of the available energy, and several particular cases are discussed. In particular, it is shown that it is impossible to confine a plasma in a Maxwellian ground state relative to perturbations with frequencies exceeding the ion bounce frequency.