From Anti-Dühring. Lightly edited translation.
Hegel was the first to state correctly the relation between freedom and necessity. To him, freedom is the insight into necessity.
“Necessity is blind only insofar as it is not understood.” [1]
Freedom does not consist in any dreamt-of independence from natural laws, but in the knowledge of these laws, and in the possibility this gives of systematically making them work towards definite ends.
This holds true in relation both to the laws of external nature and to those which govern the bodily and mental existence of men themselves — two classes of laws which we can separate from each other at most only in thought but not in reality.
Freedom of the will therefore means nothing but the capacity to make decisions with knowledge of the subject. Therefore the freer a man’s judgment is in relation to a definite question, the greater is the necessity with which the content of this judgment will be determined; while the uncertainty, founded on ignorance, which seems to make an arbitrary choice among many different and conflicting possible decisions, shows precisely by this that it is not free, that it is controlled by the very object it should itself control.
Freedom therefore consists in the control over ourselves and over external nature, a control founded on knowledge of natural necessity; it is therefore necessarily a product of historical development. The first humans who separated themselves from the animal kingdom were in all essentials as unfree as the animals themselves, but every advance in the field of culture was a step towards freedom.
At the dawn of human history stands the transformation of mechanical movement into heat: friction fire. At the furthest edge of its development to date stands the transformation of heat into mechanical movement: the steam engine. And yet, in spite of the gigantic liberating revolution in the social world which the steam engine is carrying through, and which is not yet half-completed, it is beyond all doubt that the generation of fire by friction has had the greater effect towards the liberation of mankind — for the generation of fire by friction gave man for the first time control over one of the forces of nature, thereby separating him irrevocably from the animal kingdom.
The steam engine will never bring about such a mighty leap forward in human development, however important it may seem in our eyes as representing all those immense productive forces dependent on it. However, these productive forces alone are what make possible a state of society in which there will be no more class distinctions or anxiety over the means of subsistence for an individual — a state in which for the first time there can be talk of real human freedom, of an existence in harmony with the laws of nature that have become known.
But how young the whole of human history still is! And how ridiculous it would be to attempt to ascribe any absolute validity to our present views of morality and law is evident from one simple fact: that all past history can be characterized as the history of the epoch from the practical discovery of the transformation of mechanical motion into heat, up to that of the transformation of heat into mechanical motion.