Sub topic 7
Hide and reveal with a layer mask
What this chapter covers
This chapter assumes you can open images in Photoshop, find the Layers panel, and have already placed a second photo as its own layer above the first. You should also know how to make a basic selection of a subject, which the previous chapter covered. Here you will learn what a layer mask is, how to add one, and how to avoid the errors that most often trip people up.
By the end you will be able to:
- Explain why a mask is better than erasing pixels.
- Add a mask with nothing selected, and from a selection.
- Read a mask's black, white, and gray values.
- Invert a mask and switch between editing the mask and the layer.
- Disable, link, unlink, and apply a mask.
Why use a mask instead of the Eraser
The Eraser tool deletes pixels. Once you save and close the file, those pixels are gone. If you erase too much of a person's hair, you must undo the step or reimport the photo.
A layer mask is a separate grayscale image attached to a layer. It controls which parts of the layer are visible. The layer's own pixels stay untouched underneath. If you hide too much, you paint the area back. This is called non-destructive editing, because you can change your mind at any time.
The rule to remember is short:
- White on the mask reveals the layer.
- Black on the mask conceals the layer.
- Gray shows part of the layer. The darker the gray, the more it is hidden.
How a mask is stored
A mask has the same pixel dimensions as its layer. It holds 256 levels of gray, from 0 (black) to 255 (white). The value at each pixel sets the opacity of the layer at that spot. A mask pixel at 50% gray makes the layer pixel 50% visible.
Because the mask is a separate image, it is saved inside the PSD file and stays editable. When you export a flat JPEG or PNG, Photoshop bakes the mask's effect into the final pixels.
Adding a mask
You can add a mask in three common ways. Each one gives a different starting point.
| Starting condition | How to add | Result |
|---|---|---|
| No selection | Click the **Add Layer Mask** button at the bottom of the Layers panel | White mask. The whole layer is visible. |
| No selection, with Alt (Windows) or Option (Mac) held | Alt/Option-click the same button | Black mask. The whole layer is hidden. |
| Active selection | Click the **Add Layer Mask** button | The selected area is white, and the rest is black. |
The button is the rectangle with a circle inside it, at the bottom of the Layers panel. You can also use the menu: Layer > Layer Mask > Reveal All (white), Hide All (black), Reveal Selection, or Hide Selection.
Worked example: mask from a selection
Suppose your top layer is a photo of a person on a plain background, and you want to place the person into a landscape.
- Select the person's layer in the Layers panel.
- Choose the Object Selection tool, drag a rough box around the person, and let Photoshop find the edges.
- Check the marching ants (the moving dashed outline). If they cut into the person or leave background, adjust with Shift (add) or Alt/Option (subtract).
- With the selection active and the person's layer still chosen, click Add Layer Mask.
The background disappears, and the landscape underneath shows through. The marching ants vanish, because the selection has been converted into the mask. In the Layers panel you will see a small black-and-white thumbnail next to the layer thumbnail. The white shape is the person.
Reading the Layers panel
Each masked layer shows two thumbnails with a small chain icon between them.
- The layer thumbnail on the left is the photo.
- The mask thumbnail on the right is the grayscale mask.
- A thin white frame around one thumbnail shows which of the two is active. Painting and adjustments go to the active one.
This is the source of the most common error in this topic. If you paint with black while the layer thumbnail is active, you paint black pixels onto the photo. If you paint with black while the mask thumbnail is active, you hide parts of the photo. Always glance at the frame before you paint.
Viewing the mask itself
Sometimes you need to see the mask as a black-and-white image, for example to find stray gray spots.
- Alt/Option-click the mask thumbnail to view the mask alone in the document window. Repeat to return.
- Shift-click the mask thumbnail to disable the mask temporarily. A red X appears across it. Shift-click again to enable it.
- Press the backslash key (
\) to show the mask as a red overlay on top of the image. This looks like the old rubylith film used in print work, and it shows what is hidden without losing sight of the photo.
Inverting a mask
If you get the mask backwards, with the person hidden and the background visible, you do not need to start over. Select the mask thumbnail and press Ctrl+I (Windows) or Cmd+I (Mac). Every white pixel becomes black, and every black pixel becomes white. Gray values flip too, so 25% gray becomes 75% gray.
Make sure the mask thumbnail is active before you press the shortcut. If the layer thumbnail is active, the shortcut inverts the photo's colors instead.
Linking and unlinking
The chain icon between the two thumbnails means the layer and mask are linked. When you move the layer with the Move tool or Free Transform, the mask moves with it. This is usually what you want.
Sometimes you want to move the photo while the mask stays fixed. Click the chain icon to unlink them. Then select the layer thumbnail and move or scale the photo. The mask stays where it was, like a window frame, and the photo slides behind it. Click the chain again to relink.
Common errors and fixes
| Symptom | Likely cause | Fix |
|---|---|---|
| The whole layer vanishes after adding a mask | The mask is black (Alt/Option-click or Hide All) | Invert with Ctrl/Cmd+I, or fill the mask with white |
| Background shows and the subject is hidden | The selection was of the background, or the mask is inverted | Invert the mask with Ctrl/Cmd+I |
| Painting black leaves black marks on the photo | The layer thumbnail was active, not the mask | Undo, click the mask thumbnail, and paint again |
| Mask edge is a hard, jagged cut | The selection had no softening | Feather or refine the edge (covered in a later chapter) |
| Mask shifts away from the subject after moving | The chain was unlinked | Undo, or relink and re-align |
| Nothing happens when you paint on the mask | Brush color is the same as the mask value, or the layer is locked | Check the foreground color and the lock icons |
Applying and deleting a mask
You can finish with a mask in two ways. Both are destructive in some sense, so save a copy of your PSD first.
- Delete the mask: right-click the mask thumbnail and choose Delete Layer Mask. The layer returns to fully visible and the mask is discarded.
- Apply the mask: right-click and choose Apply Layer Mask. Photoshop permanently erases the hidden pixels from the layer, then removes the mask.
For a composite you plan to edit later, do neither. Keep the mask in place. A layered PSD with masks intact lets you revisit any edge.
A note on Smart Objects
If your layer is a Smart Object, a mask still works the same way. The mask applies to the Smart Object as a whole, outside the embedded image. This means you can resize or replace the contents later while the mask stays attached. Applying a mask to a Smart Object is not possible without rasterizing it first, which is another reason to leave masks unapplied.
Check your understanding
Exercise
You add a layer mask with a selection active, and the photo's subject disappears while the background stays visible. Name two ways to fix it without redoing the selection, and say which thumbnail must be active for the fix to work.
Show answer
Select the mask thumbnail and press Ctrl+I (Windows) or Cmd+I (Mac) to invert it. Alternatively, delete the mask, then choose Select > Inverse and add the mask again. The mask thumbnail must be active for the first method. If the layer thumbnail is active, the shortcut inverts the photo's colors instead.
Exercise
A mask pixel has a value of 75% white (25% gray toward black). Roughly how visible is the layer at that pixel, and what would the value be after inverting the mask?
Show answer
The layer is about 75% visible at that pixel. After inverting, the value becomes 25% white, so the layer is about 25% visible.
Exercise
You resize a masked layer with Free Transform, and the mask edge no longer lines up with the subject. What is the most likely cause, and how do you confirm it?
Show answer
The layer and mask are probably unlinked. Look for the missing chain icon between the layer thumbnail and the mask thumbnail. Undo the transform, click the space between the thumbnails to relink them, and transform again.