For macroscopic systems, the statistical formulation of entropy implies that the second law is overwhelmingly likely to be accurate. It does, however, allow a non-zero probability to it being measurably inaccurate. Maxwell invented the demon to demonstrate that there could be situations in which the second law is violated. Maxwell describes the demon as follows (quoted in , p. 4):
... if we conceive of a being whose faculties are so sharpened that he can follow every molecule in its course, such a being, whose attributes are as essentially finite as our own, would be able to do what is impossible to us. For we have seen that molecules in a vessel full of air at uniform temperature are moving with velocities by no means uniform, though the mean velocity of any great number of them, arbitrarily selected, is almost exactly uniform. Now let us suppose that such a vessel is divided into two portions, A and B, by a division in which there is a small hole, and that a being, who can see the individual molecules, opens and closes this hole, so as to allow only the swifter molecules to pass from A to B, and only the slower molecules to pass from B to A. He will thus, without expenditure of work, raise the temperature of B and lower that of A, in contradiction to the second law of thermodynamics.
A simpler model of a demon which functions in a similar way is the so-called pressure demon. A pressure demon could be a valve between two chambers of gas which opened or closed to allow molecules to travel one way but not the other. If placed between two chambers of initially at equilibrium, a pressure difference could be created by the demon, and this could be used to do work. This would violate the second law. The energy to do this work would come from the random motion of the molecules in the gas. If such a demon could be made, the second law of thermodynamics could be violated and the thermal energy of our surroundings could be used as a source of energy.