A Layer Mask lets you control what parts of the layer are hidden/visible. To make part of a layer visible you paint over it with white and to hide it you use black. If you want to partially show part of the layer you can use grey. This ability to hide/reveal parts of layers makes Layer Masks the perfect tool for blending too images together seamlessly.
Open your images
Open your images up in Photoshop and drag one image into the other with the Move tool so each of the images appear on separate layers. In our example it's a landscape shot and a photo of a sheep of which we are going to blend into the background. If, like ours, your subject is too big for the background go to Edit>Free Transform and adjust the anchor points until they fit.
Select the layer you want to create the mask on, which in our case is the image of the sheep, and select the Layer Mask icon from the bottom of the layers palette. This will add a Layer Mask icon on the layer you selected and for the moment it will be completely white as none of the layer is hidden by the mask.
At the moment it looks like we have two separate images but we can use the Layer Mask to hide the area surrounding the subject to seamlessly blend the two layers together. To do this, select the Brush tool, make sure the foreground colour is set to black and paint over the part of the layer you want to hide. If you paint too much away change the foreground colour to white and paint back over the area you've just removed.
Shot before and after:
If you want to blend too images together gradually you can use the Gradient tool. Drag one image into the other, as you did previously, so you have two layers.
As you can see with our example the top layer is overlapping the bottom one but if we used the Brush tool on a Layer Mask to remove it the backgrounds wouldn't blend together and the image wouldn't look right. However, if you use the Gradient tool, creating a gradient that's black at the left and gradually turns into grey, will seamlessly blend the images together.
To do this, select the Gradient tool and click on the box towards the top of the work area that has the Gradient in it. This will open the Gradient Editor where you can increase/decrease the amount of black, grey and white is in the gradient. The more black you have the more of the layer will be hidden when you apply the gradient.
Before you use the gradient make sure you've created a Layer Mask on your top layer then starting where you want most of the image to be hidden, click and drag your mouse to where you want to blend to end. If the Gradient takes too much of your image away you can switch to the Brush tool making sure white's set as your foreground colour and paint the detail back in.