Hansteen was born in Christiania as the son of Johannes Mathias Hansteen (1744-1792) and his wife Anne Cathrine Treschow (1754-1829).
The intention was for Hansteen to become a naval officer, but since his father died when Hansteen was young, this plan did not materialize.