Hansteen was born in Moss, and graduated there as a cand.jur. (Candidate of Law) in 1840. From 1840 to 1842 he was a deputy judge at the Moss District Court in Moss. He was a judge in what was Norway's last trail that ended in pillory, making one embarrassed in public. He later worked as a "district stipendiary magistrate" of the Sør-Østerdal District Court from 1854 to 1869. He later worked at the Solør District Court from 1869 to 1879. In 1879 he became a Supreme Court Assessor for the rest of his life.