Hardy's family was Anglican, but not especially devout. He was baptised at the age of five weeks and attended church, where his father and uncle contributed to music. However, he did not attend the local Church of England school, instead being sent to Mr Last's school, three miles away. As a young adult, he befriended Henry R. Bastow (a Plymouth Brethren man), who also worked as a pupil architect, and who was preparing for adult baptism in the Baptist Church. Hardy flirted with conversion, but decided against it. Bastow went to Australia and maintained a long correspondence with Hardy, but eventually Hardy tired of these exchanges and the correspondence ceased. This concluded Hardy's links with the Baptists.
The irony and struggles of life and a curious mind led him to question the traditional Christian view of God:
- The Christian god – the external personality – has been replaced by the intelligence of the First Cause...the replacement of the old concept of God as all-powerful by a new concept of universal consciousness. The 'tribal god, man-shaped, fiery-faced and tyrannous' is replaced by the 'unconscious will of the Universe' which progressively grows aware of itself and 'ultimately, it is to be hoped, sympathetic'.
Hardy's religious life seems to have mixed agnosticism, deism, and spiritism. Once, when asked in correspondence by a clergyman about the question of reconciling the horrors of pain with the goodness of a loving God, Hardy replied,
- Mr. Hardy regrets that he is unable to offer any hypothesis which would reconcile the existence of such evils as Dr. Grosart describes with the idea of omnipotent goodness. Perhaps Dr. Grosart might be helped to a provisional view of the universe by the recently published Life of Darwin and the works of Herbert Spencer and other agnostics.
Hardy frequently conceived of, and wrote about, supernatural forces, particularly those that control the universe through indifference or caprice rather than any firm will. He also showed in his writing some degree of fascination with ghosts and spirits. Even so, he retained a strong emotional attachment to the Christian liturgy and church rituals, particularly as manifested in rural communities, that had been such a formative influence in his early years, and Biblical references can be found woven throughout many of Hardy's novels.
Hardy's friends during his apprenticeship to John Hicks included Horace Moule (one of the eight sons of Henry Moule), and the poet William Barnes, both ministers of religion. Moule remained a close friend of Hardy's for the rest of his life, and introduced him to new scientific findings that cast doubt on literal interpretations of the Bible, such as those of Gideon Mantell. Moule gave Hardy a copy of Mantell's book The Wonders of Geology (1848) in 1858, and Adelene Buckland has suggested that there are "compelling similarities" between the "cliffhanger" section from A Pair of Blue Eyes and Mantell's geological descriptions. It has also been suggested that the character of Henry Knight in A Pair of Blue Eyes was based on Horace Moule.