Hartmann was born in Berlin, the son of Prussian Major General Robert von Hartmann and was educated with the intention of him pursuing a military career. In 1858 he entered the Guards Artillery Regiment of the Prussian Army and attended the United Artillery and Engineering School. He achieved the rank of first lieutenant but took leave from the army in 1865 due to a chronic knee problem. After some hesitation between pursuing music or philosophy, he decided to make the latter his profession, and in 1867 obtained a Ph.D. from the University of Rostock. In 1868 he formally resigned from the army. After the great success of his first work "Philosophy of the Unconscious" (1869)—the publication of which led to Hartmann being embroiled in the pessimism controversy in Germany—he rejected professorships offered to him by the universities of Leipzig, Göttingen and Berlin.