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.
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, coupled with his naturally 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'.

 
Scholars have debated Hardy's religious leanings for years, often unable to reach a consensus.
Once, when asked in correspondence by a clergyman, Dr. A.B. Grosart, about the question of reconciling the horrors of human and animal life with "the absolute goodness and non-limitation of 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, a force he called The Immanent 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.

Throughout his life, Hardy sought a rationale for believing in an afterlife or a timeless existence, turning first to spiritualists, such as Henri Bergson, and then to Albert Einstein and J. M. E. McTaggart, considering their philosophy on time and space in relation to immortality.
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. 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, coupled with his naturally 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'.
 
Scholars have debated Hardy's religious leanings for years, often unable to reach a consensus. Once, when asked in correspondence by a clergyman, Dr. A.B. Grosart, about the question of reconciling the horrors of human and animal life with "the absolute goodness and non-limitation of 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, a force he called The Immanent 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.
Throughout his life, Hardy sought a rationale for believing in an afterlife or a timeless existence, turning first to spiritualists, such as Henri Bergson, and then to Albert Einstein and J. M. E. McTaggart, considering their philosophy on time and space in relation to immortality.
Thomas Hardy