Q: What's a good portrait lens?
A: As usual, it depends.
Any lens can be used as a portrait lens, some work better than others. Traditionally, lenses in the 85-135mm range on film are considered "portrait" lenses. (That translates to around 50mm-105mm on DX bodies.)
They primary advantage to using a long lens for portraits, as opposed to a normal lens (like a 50mm on film or a 35mm on DX) is that with a longer lens, you stand a bit farther back in order to fill the frame. This gives a different perspective, which is usually considered more flattering to the facial features. (Moving closer to or farther away from the subject changes the apparent size of objects at different distances.)
It is important to note that it is not the lens in itself that changes the perspective, but rather the change in camera position which the lens allows/encourages/requires. In a pinch, you can always use a normal lens and just stand back a bit, and then crop in during post-processing.
A secondary advantage to using a longer lens when shooting against a busy background is that it allows for greater subject isolation reduced visual clutter. Also, some particular portrait-length lenses have been designed specifically with portraiture in mind, and those lenses may have superior bokeh, better sharpness at the right distances, or other desirable attributes.
Of course, if you stand too far away, the perspective may cease to be flattering and instead take on more of a surveillance/paparazzi aspect, which is not desirable, either. Also, you may at times want the exaggerated features that come with getting in very close, in which case you would need a wide lens.
You may also need a normal or wide angle lens in order to accommodate a larger field of view for group shots or environmental portraits, where the context becomes an essential part of depicting the person.
The traditional focal length for portraiture on 35mm film was between 85 mm and 135 mm, with 105mm often being the preferred compromise. That means that to keep the same field of view on an APS-C DSLR like the D40, you'd be looking at lenses somewhere between 50 mm and 90 mm. This doesn't mean you need to use these lenses, though. Depending on your desired outcome you could use any length.
Usually, portrait photographers seek a clean and simple background to their images, which in most cases requires a large aperture, generally f/4 or faster. Often the photographer will want to sacrifice some sharpness in favour a background from which the subject stands out, and so will select an aperture of about f/2, or sometimes even f/1.4 or f/1.2. Because of the narrow depth-of-field you may want to shoot at a higher aperture before you see in the final image and notice that you've accidentally focused on the ear, and the eyes are out-of-focus. Accordingly, f/2.8 or thereabouts if usually a good compromise. This all depends on the distance from the subject, focal length and overall goal of the photo. In general, the eyes should always be in focus since this is where people naturally view a persons face.
If your subject is in a studio or you wish to use some of the background a medium aperture (f/8 to f/11) is generally best. In general the image will be sharper and the focusing (especially when using manual focus) will be far less critical.
As before, lenses below 50 mm focal length are usually avoided in portraiture. They can, however, be quite useful for group or environmental portraits. The Sigma 30mm 1:1.4 is popular as a fast wide-angle that autofocuses on the D40, but the Nikkor 35mm 1:2 is a cheaper and smaller lens that is also compatible with full-frame cameras. Ultra-wides can be used as a portrait lens for those who want an exaggerated look on the face, however, your subject may not be as happy with the photo. Sub-50mm lenses should be used more with group shots or where you have a very short working distance.
These lenses offer a "normal" perspective on a film camera, but on a DX camera, they're almost at the short end of the traditional portraiture range. Nikon offer several 50 mm lenses, the slowest being f/2, which are for the most part cheap and plentiful. The AF Nikkor 50mm 1:1.8D is by far the most cheap and plentiful, but there is also an f/1.4 version. You can get them even cheaper in pre-AI or AI / AI-S manual-focus versions. If autofocus is required on the D40, expect to pay more for a Nikkor or Sigma 50/1.4 with AF-S/HSM. These lenses are notoriously sharp for the cost and should be found in every photographers bag.
Macro lenses can make excellent portrait lenses, offering very good optical performance. In most cases though they lack the fast apertures of their non-macro brothers. This makes it harder to isolate the subject, especially if there's visual clutter in the background.
If you want to save space in your bag by doubling-up roles for your lenses, good macro lenses that are also good portrait lenses include the Micro-Nikkor 55 mm 1:2.8 and 1:3.5 and the AF Micro-Nikkor 60mm 1:2.8 and its AF-S replacement.
Of the two Nikkors usually regarded as prime portrait lenses, the 85mm 1:1.4 is the shorter and faster version. Available as pre-AI, AI, AI-S, or AF, it's known for especially pleasing bokeh and exquisite sharpness.
Of course, with this reputation comes cost. The 85/1.8 and 85/2 provide cheaper alternatives, but they're still quite pricey, even used. You probably won't suffer from buyer's remorse, though.
Getting into the tradition range for the head-and-shoulders portrait, there are several good options.
I mentioned before the two prime portrait Nikkors - the other is the Nikkor 105mm 1:2.5. Sharpness, bokeh, it's all there. Two versions exist, the earlier Sonnar design that supposedly offers slightly better bokeh, and the later Gauss/Xenotar type that is marginally sharper.
Other options include the 105/1.8, which is really just a stop more on the 105/2.5, with a corresponding increase in size, and the Series E 100mm 1:2.8, which is competent and cheap.
There's also the AF DC-Nikkor 105mm 1:2, which is very, very sharp and very, very good. The 'DC' stands for Defocus Control, which is a fancy term for what is essentially bokeh optimisation. On the down side, though, it's big and expensive.
100-105 mm Macro
Same as with the 50-60 mm macro lenses, the various 105mm Micro-Nikkors are solid performers for portraits too. The AF-S VR Micro-Nikkor ED 105mm 1:2.8G is the newest version.
135 mm and Up
This getting to the end of the range that you'd be wanting to use in most portraits, but a 135 mm lens can be useful for working outdoors or at a distance. The 135 mm 1:2.8 and 1:3.5 Nikkors are more than decent, offering good performance at a low price.
Zoom lenses can also be excellent for portraiture, especially when you and/or the subject are moving about. Bear in mind though that in most cases they are also larger and more expensive that prime lenses.
- AF-S Nikkor 24-70mm 1:2.8 - High-quality mid-range zoom. Fast and sharp, often favoured for weddings, but length is probably insufficient for individual portraits.
- AF Nikkor 80-200mm 1:2.8 and AF-S Nikkor 70-200mm 1:2.8 - both professional-standard tele-zooms for photojournalism, these lenses also offer excellent image quality, and are a good length for head-and-shoulders portraits. They are however very heavy.
- AF-S DX (VR) Nikkor 55-200mm 1:3.5-5.6 and AF-S DX VR Nikkor 18-135mm 1:3.5-5.6 - Both cheaper beginner lenses, they're still more than usable under good light.
- Sigma 50-150mm f/2.8 HSM