Standard method for creating a layer mask: Start by using your favourite selection tool to draw a rough shape around the hair. Then, click the mask icon in the layers panel. If you click the eyeball beside your background layer, you might notice that the only thing you can see now is the hair. If so, you have successfully created a mask.
Anything you draw on this mask (shown in the layers panel as a black and white square to the right of the layer) in black will disappear and anything you draw in white will be visible. To edit the mask more closely, go in with a small brush of medium softness and draw black on the parts you don’t want until the hair is floating on its own in the transparent background checkerboard.
Once you’ve formed your mask, you can double click it to edit the mask’s smoothness, fade and contrast. You can also shift the outline of the mask further or closer using the “shift edge” controls. When dying your hair to be lighter or more vibrant, you might need a more precise mask to bring the effect out to all those edges. When making your hair darker, the final effect usually looks more realistic with a soft mask. Of course, these aren’t hard and fast rules. Feel free to revisit this step and experiment with the mask options after you’ve coloured the hair, since it’s often easier to see when you’re working on top of your original photo.