UPDATE: See my note at the bottom!
Lots or religious people raise their kids with religion, thinking that this will make them more religious when they're adults. Atheists do the same by not raising their kids with religion.
Understanding descriptions of "percentages of variance accounted for" is kind of confusing, so I'd like to explain it with a metaphor.
Imagine that you can represent how religious someone is (their "religiosity") with marbles in a bowl. Each person gets 100 marbles. The more blue marbles are in the bowl, the more religious that person is. The more white marbles are in the bowl, the less religious. So a super duper religious person would have mostly blue marbles in there, with only one or two white ones, and a complete skeptic would have very few blue ones. Most people would be somewhere in the middle.
So to say that genes account for 40% of the variance in religiosity means that in a given person's bowl of marbles, the color of forty of them will be determined by his or her genes. How they are raised by their parents determines the color of only three of them.
So why do so many people resemble their parents in religiosity? Well, first of all, when you look closely, exceptions aboud. Often you'll find among siblings a great variety in religious practice. But the reason for the similarity is that the parents don't just contribute their child-rearing practices, they contribute their genes too. We just tend to attribute more weight to upbringing than we should, probably because it's something we can do more about, and takes a lot of our attention in our lives.
Waller, N. G., Kojelin, B. A., Bouchard, T. J., Lykken, D. T., & Tellegen, A. (1990). Genetic and environmental influences on religious interests, attitudes, and values: A study of twins reared
apart and together. Psychological Science, 1(3), 138-142.
Addendum added August 29, 2013:
This post has received an enormous number of views, and a fair amount of criticism that I would like to respond to. First, yes, as one commenter notes, I misreported some of the numbers. Raising of kids appears to account for 11% of the variance, not 3%. Still small, but larger than I initially reported. This was religiosity as measured by "religious leisure time interests," as opposed to "religious occupational interests." Also, the genetic basis was higher than I reported, at 47%. I apologize for getting then numbers wrong.
Others have asked how many twins were studied. There were 53 pairs of monozygotic twins studied, reared apart. This might not seem like a high number, but twins raised apart are not easy to find. Others have criticized that this is an old study (implying, I guess, that the genetic contribution to religiosity would have changed in the last 23 years, which seems implausible to me.) I will say that this was a part of the famous "Minnesota Study of Twins Reared Apart." It is a well-known, respected study. You can read about it here:
Again, these studies are difficult to do. I did manage to find a somewhat more recent replication, however, which found a genetic correlation of 43%.
Olson, J. M. & Vernon, P. A., Aitken Harris, J. & Jang, K. L. (2001). The heretibility of attitudes: A study of twins. Journal of Personality and Social Psychology, 80(6), 845--860.
Also, some have asked what the other percentage is from. In the Waller et al. study, religiosity was 47% genetic, 11% family environment, and 42% non-family environment. This means that, like many other psychological things, the environment-genes contribution is roughly 50%-50%.
Finally, I had been accused of "bias." Nobody said what the bias was, however. If religiousity is 43%-47% genetic, so is atheism.