Hagenbach was born at Basel, where his father was a practising physician, and a professor of anatomy and botany in the university. His preliminary education was at a Pestalozzian school, and afterwards at the gymnasium, whence in due course he passed to the newly reorganized local university. He early devoted himself to theological studies and the service of the church, while at the same time cherishing and developing broad "humanistic" tendencies which found expression in many ways and especially in an enthusiastic admiration for the writings of Herder.