Although I've branched out, macro is still my photographic
raison d'être.
General thoughts:
Some lenses claim to be macro, but only do close-up. Which may be good enough for botanicals (flowers) or possibly product pics, but maybe not for bugs, etc. Canon's EF 24-70mm L, for example, has a "macro" range but its max magnification is only 0.29x (vs. 1:1 like a true macro/micro lens). Semantics aside, close-up is actually what a lot of people want when they say macro. If botanicals are what trips your trigger, a macro lens may not even be necessary as long as you have glass that has a reasonable minimum working distance, maximum magnification, and reasonable sharpness.
Speaking of which, dedicated macro/micro lenses are the ultimate solution if you really want to see the detail in the compound eye of a bee or demand seriously sharp closeups. This is really the best solution if you can afford it,
and if you find you regularly shoot in the 1:2 (0.5x) to 1:1 (1x) range. The 100mm/105mm macro lenses give you about double the working distance (around a foot from end of the lens to your subject) at 1:1 vs. a 50mm/60mm. There are even longer macro/micro lenses in the 150mm/180mm/200mm range that will give you even more working distance but that distance starts to work against you with those razor thin DOFs; you'll eventually want some sort of ring light or closeup light (I don't know which one is compatible with your D40). And a decent tripod that will get really low or let you hang your camera
horizontally or upside down. If your camera doesn't support live view with magnification for focusing, your job will be
much harder.
Two other solutions for macro/closeup work:
Extension tubes are basically tubes with electronic connections in the tube and air in the middle. Yes, in the bargain for shorter focusing distance you lose infinity focus, but infinity focus support is what makes true 1:1 macro lenses hunt; it's not needed when you are focusing on a dragonfly. The other useful thing about extension tubes is that they are temporary, easy to remove when you are done with them. Extension tubes are most useful for primes and zooms with shorter focal lengths; that Canon 24-70mm L that I mentioned above can move into true macro range with a 25mm or 30mm extension tube. N.B. For some reason the
Nikon extension tubes don't have built-in contacts to enable autofocus; if you have a D40 that may not matter. Otherwise the tubes from Canon or Benko (
Nikon or
Canon) will support AF, etc.
Diopters are basically clear filters that have additional magnification instead polarizing or UV filters. Canon's 500D Close-up Lens is appropriate for longer focal lengths, say, in the 70mm to 200mm range. (I have no idea why this has the same name as the international name for the T1i, I doubt anyone at Canon knows.) At $100-$150, these can be a great solution for people who only occasionally shoot macro. The main problem with these is that they mount like a filter at the end of the lens, which causes the normal filter sizing issues you have with an other (ND, polarizing, UV) filter: the 72mm version is going to need help to mount on 77mm threads, and vice versa. If you shoot Nikon, don't stress that this is a Canon product because the filter thread pitch is identical for both types of lenses. (I saw a Nikon version once at a botanical garden shoot, but was told that it was a relic as Nikon had stopped making them years ago.)
Misc.:
Years ago I used bellows or reversed a wide angle lens, but no more. Extension tubes are just too cheap and easy to use to bother with bellows, and reversing lenses is asking for dust in your lens (ask me how I know).
Also, Canon has an extreme macro manual focus 5:1 (5x) lens, but that won't work with your D40, and its a fussy beast that requires a special focusing rails on a tripod as the lens has no focusing element of it's own. Though if you want the whole frame filled with just the point of a pencil or grain of rice or a part of a bug's eye, that's the only game in town. Ultra fidgety and
not the place to start.
This got more longwinded than I intended, but the gist is that extension tubes from Benko for your shorter Nikon lenses even a 50mm, and a tripod with a center column that will go horizontal or even upside down, is probably where I'd start if I only had limited dollars to spend and wanted to get into macro or closeup photography. Or a diopter if I had a good 70-200mm zoom to work with.