Hagen was born in Königsberg, East Prussia (today Kaliningrad, Russia). He studied at the University of Königsberg (where Immanuel Kant was a professor of philosophy during that period) mathematics, architecture and civil engineering. After his examination he became an appointee and was responsible for hydraulic engineering projects.
In 1824 the mercantile community of Königsberg hired him as buildings conducteur, in 1826 he became a harbour inspector in Pillau, in 1830 he changed to Berlin in the construction direction. Starting 1834 he taught at Berlin.