Aha, I had this many times (I use a D40 too).
As others have said, its dust on the sensor, I use a tiny amount of lens cleaning fluid on a cotton bud to clean it. If you dont know how to get to the sensor, you want to find 'Mirror Lock-Up' in the menu.
If you dont feel safe doing it, take it to a camera store, if they break it, they pay for it!
