Let's start by defining what a layer mask does at its most basic level: it makes certain parts of a layer transparent, allowing the image layers below to remain visible. Masks do this without deleting any image-forming data, as you would if you simply erased layer details. (If you're a visual thinker, imagine a layer mask as a print overlaid with clear acetate—kind of like the way cartoons used to be made. Image forming areas are visible on the acetate layer, whereas masked away areas are clear.) It's in the photographer's ability to fine-tune a mask in order to dictate what is visible and what shows that gives layer masks their ultimate power.
Once you've got an image comprised of a background and at least one layer, you're able to employ layer masks. (The layers can be literally anything you like—copies of the same basic image, or separate photographs or image elements that you want to composite together.) In the layers palette, with the layer you'd like to mask actively selected, click on the Add Layer Mask icon at the bottom of the frame. It looks like a rectangle with a circle inside it. Boom: you've just employed a layer mask.
By default, this method creates a mask that is clear, represented by a fully white mask icon adjacent to the active layer's thumbnail in the layers palette. Option-clicking when you create the mask does the opposite: creating an all-black, fully opaque layer mask.
Selections are crucial when working with masks, and they can be made after the mask's creation, or before. If you've already made a selection anywhere in your image, when you click on the Add Layer Mask icon in the layers palette your mask will automatically conform to the selection—making the selected area visible and the rest transparent. If you're making your selection after creating the mask, your selection tools require reading specific pixels you need to be sure to click on the layer thumbnail icon in the layers palette to allow pixel-specific selection tools (magic wand, quick select, etc.) to read the image detail pixels. This is how you switch back and forth between the layer and the mask, so that whatever changes you apply (painting on the mask, for instance) will be applied where you want them—on the layer or on the mask. Again, clicking the layer thumbnail in the layers palette activates the image layer and clicking the mask thumbnail activates the mask.
The thing to remember about a layer mask is the fundamental basic that black makes the mask clear, showing through to the layer beneath. White is opaque, allowing the elements of the masked layer to remain visible. Shades of gray represent the various opacities in between. You can see this in action, for instance, when you click on the mask in the layers palette, and then start painting with a black paintbrush on your image. Painting is the most basic way of altering a mask. You can paint with a hard-edged brush, or a soft brush, a big brush or a small brush, or any other brush you can imagine.
While you paint—whether it's black, white or a shade of gray—on the main image, the tiny little thumbnail of the mask in the layers palette will show you where you've painted on the mask. It's a helpful way to get an idea about your mask's shape, but to get a real detailed view, option-click or shift-option-click the mask thumbnail in the layers palette and the whole image will show the mask in black and white, or the image combined with the mask in red.
Command-clicking (control-click in Windows) on the layer mask thumbnail in the layers palette will automatically turn the mask into a selection. Right-clicking the layer mask will open a menu with a few useful options—including allowing you to temporarily disable the mask, permanently delete the mask, apply the mask to the layer (rendering the masks transparent areas into transparency on the layer itself), convert the mask into various types of selections, and perhaps most powerfully, refine the layer mask. This last tool functions much like the Refine Edge tool does on a regular selection. It's a powerful tool for fine-tuning a mask.
Do you ever work with adjustment layers? If so, you've already worked with layer masks, because whenever you create an adjustment layer, a layer mask is automatically created to accompany it. This serves as a reminder that you can easily refine and customize the adjustment layer's effect with a custom layer mask.
Remember, since you're simply painting black, white and shades of gray on a mask in order to adjust its local opacity, you can use custom painting tools to work on the mask as well—like the gradient fill. It's a great way to blend a layer's effect subtly from one part of the frame to another.
If you learn nothing else about layer masks, commit this to memory: instead of erasing a layer's details, using a layer mask makes those details invisible without deleting them—and this offers increasing control along with the ability to refine or undo changes should you need to alter them down the road.