here is a small break down
the D40, in order to be made cheaper and lighter, does NOT have an auto focus motor in the body.................this means that you can only use lenses with auto focus motors IN THE LENS........these lenses are expensive
the D80 DOES have an autofocus motor in the body, so you can use cheaper lenses for it
so lets say, hypothetically, that I want a camera body + wide angle lens + 300mm zoom + macro + 55-200 zoom + 500mm wild life lens
that combo would actually be cheaper if my body was a D80, since I could get cheaper lenses
to get those lenses in AF-S or AF-I (the only kind the D40 can use) would cost $$$$$$$$$$$$$$$$$$$$$
I should also mention that you CAN use the cheaper lenses on the D40, but you will NOT have auto focus....how important that is to you is your decision to make, but manual focus is very challenging to a beginner, I wouldnt even consider it for myself since Ive only been shooting for a few months and am nowhere near good enough for full time manual focus
I am a D40 owner and I love it, but if I had it to do again I would have gotten the D80 for that reason....I am actually going to buy another body and keep the D40 because it is so excellent for taking "on the go"
edit: here is an example
here is a 70-300 mm zoom lens that is AF (would autofocus on the D80, but not the D40)
http://www.bhphotovideo.com/c/product/207359-USA/Nikon_1928_Zoom_Telephoto_AF_Zoom.html
here is the similar lens that would work on the D40:
http://www.bhphotovideo.com/c/product/449088-USA/Nikon_2161_70_300mm_f_4_5_6G_AF_S_VR.html
D80 version $135
D40 version $479 (the D40 version has a few other features that the first one doesn't have (like the VR feature), but the point is still the same)