Energy of magnetized vs not magnetized ferromagnet? A ferromagnet conststs of many, many microscopic magnetic dipoles that can be pointed in different orientations. If the ferromagnet is not magnetized by applying an strong external magnetic field, the dipoles will be arranged into small grains of which each grain will have a common direction for all dipoles within that grain, but for which the orientation will differ between different grains. I am wondering a couple of things about this:

*

*Is an unmagnetized ferromagnet arranged into grains like this – in contrast to having all dipoles pointing in the same direction – because it is a relatively low energy configuration, or is it simply arranged like this because this state has a much higher entropy, and is thus much more likely to occur naturally?


*After a ferromagnet has been magnetized by applying a strong external magnetic field and turning it into a permanent magnet, does the total energy of the ferromagnet increase or decrease?
My intuition says that the reason dipoles arrange themselves to point in the same direction at all, even if this is just locally within small grains, is because this is a lower energy configuration than having all dipoles point in different directions, and therefore if all dipoles in the whole ferromagnet would point in the same direction, this would be an even lower energy configuration, probably with energy close to the ground state energy of the system (given a certain temperature, if that makes any sense).
However, other people state that it is possible to extract energy from a permanent magnet, which I guess would mean that the magnetized state of a ferromagnet is a relatively high energy state. If a permanent magnet has a higher energy than the ferromagnet it was created from, why don't the dipoles in permanent magnets spontaneously disalign and turn the exessive energy into heat (thermal energy), since this must be a much higher entropy state?
 A: Short answer: think energy, not entropy.
Long answer:
Think of the field lines evidenced by small iron particles in presence of a bar magnet. They form curved shapes, slowly reverse direction and end up connecting the magnet's North with its South pole, right? Now think of the same kind of magnetic field lines being generated by one of the magnetic domains inside your ferromagnet. These indicate the preferred orientation for other domains, at different positions, and would lead to a cancelling of the total magnetic moment. If left to their own devices, the domains within a ferromagnet will adopt a disposition that minimizes the total magnetic moment. This is actually explained in Wikipedia:

Why domains form
The reason a piece of magnetic material such as iron
spontaneously divides into separate domains, rather than exist in a
state with magnetization in the same direction throughout the
material, is to minimize its internal energy. A large region of
ferromagnetic material with a constant magnetization throughout will
create a large magnetic field extending into the space outside itself
(diagram a, right). This requires a lot of magnetostatic energy stored
in the field. To reduce this energy, the sample can split into two
domains, with the magnetization in opposite directions in each domain
(diagram b right). The magnetic field lines pass in loops in opposite
directions through each domain, reducing the field outside the
material. To reduce the field energy further, each of these domains
can split also, resulting in smaller parallel domains with
magnetization in alternating directions, with smaller amounts of field
outside the material.


On the second part of your question, the demagnetization of a ferromagnet, while thermodynamically spontaneous, is kinetically blocked by an energy barrier which needs to be overcome. If you consider the energetic effect of a small reorientation of one of the magnetic domains, it will always be energetically uphill, so it just does not happen (at temperatures below the Curie temperature). This is how ferromagnets remain magnetized for a long time, in a metastable state.
Addendum:
What about the alignment within the magnetic domains? Through-space magnetic interaction, the one we represent through field lines, is not the only magnetic interaction. There also exists magnetic exchange (and superexchange), by which the direct overlap between magnetic orbitals (or mediated by a bridging atom), and which can favour the ferromagnetic alignment between two local magnetic moments. This interaction can be very strong, but, being local, is very susceptible to defects. Alongside domain barriers, there magnetic ordering breaks down, separating two well-ordered regions, or domains.
A: The equilibrium of a state is the constra-balance of two factor: internal energy and entropy. Puting these two factors in math form becomes the Helmholtz free energy:
$$ 
  F  = U - TS \tag{1}.
$$
The equilibrium of a state is to reach minimum of free energy.
(1) As long as the internal energy, $U$, is concerned, the energy is a all-aligned magnet has lower internal energy than the multi-grain configuration.Because the ferromagnetic interaction, $H = J_{ij} \vec{S}_i\cdot \vec{S}_j$, the coupling constant $J_{ij}$ is negative.
(2) As consider the equilibrium state, we need a state of minimum free energy under a given temperature. Examining from Eq.(1), the weighting of entropy is proportional to temperature. At zero kelvin, the internal energy is solely determine the equilibrium. But at high temperature, the entropy becomes more important.
A: If question 1. is a question about equilibrium, the general answer is:

*

*we must first of all specify which constraints define the possible equilibrium states – for example constant temperature, or magnetization, and so on. (You understand that this specification is important because otherwise any state can be an equilibrium state: we just need to fix the system's state variables at those specific values.)


*The general principle is that the equilibrium state is the one that maximizes the entropy with respect to the specified constraints (see eg Callen, § 1.10 Postulate II). For particular constraints this maximization is equivalent to the extremization of other quantities (see eg Callen, ch. 6): for example minimization of Helmholtz free energy when the temperature is constrained, or Gibbs free energy, or other thermodynamic potentials. In particular we must consider whether the external field or the magnetization are constrained, and this often leads to free energies built by adding or subtracting a term proportional to $MH$, where $M$ is the magnetization and $H$ the external magnetic field.
This is also true for the ferromagnets. For these matters see for example

*

*Callen: Thermodynamics: an introduction to the physical theories of equilibrium thermostatics and irreversible thermodynamics
and also this very insightful essay:

*

*Wightman: Convexity and the notion of equilibrium state in thermodynamics and statistical mechanics.


Regarding question 2., there is no definite answer to your question because the process is not completely specified. The change in internal energy depends on the work done on the system by the magnetic field, by other kinds of work (if any), and on the heat exchanged by the system, at the very least. So we need to specify whether the change in the external field happens in adiabatic conditions, or at constant temperature, and so on.
As an example, if we take as state variables the entropy $S$ and magnetization $M$, the reversible change in internal energy is
$$\mathrm{d}U(S,M) = T\ \mathrm{d}S + \mu H\ \mathrm{d}M \ ,$$
with $\mu>0$. Paraphrasing Laughlin, in a reversible adiabatic process "applying a magnetic field displaces (aligns) the magnetic moments and hence work is done on the system, thereby increasing its internal energy".
 Regarding your final point, yes a ferromagnet demagnetizes, but over scales of hundreds or thousands of years. I leave you to agaitaarino's concise explanation for this.
Further references for the thermodynamics and thermostatics of ferromagnetic materials – which is extremely interesting – besides Callen's and Wightman's works above:

*

*Astarita: Thermodynamics: An Advanced Textbook for Chemical Engineers, ch. 13;


*Laughlin: Magnetic Transformations and Phase Diagrams.
