One of the principles of the Rules of Golf is to play the ball as it lies. Rule 9 covers what to do when your ball at rest moves. As with any good rule, Rule 9 has a number of exceptions. There are many places and ways that a ball can move on the course, each requiring you to proceed in potentially different ways.

Let’s assume you've started the hole and your ball is in play.
First, you must determine what caused the ball to move. Was it accidental or deliberate? Was it moved by natural forces (such
as wind or gravity), by you or by another player?

What caused the ball to move determines whether to replace the ball or play it as it lies, and whether a penalty is assessed.
If your ball was moved by natural forces, everywhere except the putting green, you play the ball wherever it moved to with no
penalty. What if your ball is in the fairway on a slope near a penalty area and before you get to the ball it rolls into the penalty
area?

You must play the ball as it lies or take penalty area relief. There is no penalty for your ball being moved by natural forces.
The exception is when your ball is on the putting green. If your ball moves after you marked and replaced the ball, then you must replace the ball on the original spot. If you have not yet marked and lifted the ball then you play it from where the ball moved
to. If it rolls into the hole, the ball is holed!

If you, the player (or your caddie or partner), moves your ball in play, then you get one penalty stroke and the ball must be
replaced.

Of course, there are some exceptions to when you are allowed to lift or move your ball without penalty. There is no penalty for moving your ball while taking relief, when you accidentally move
your ball while searching for it, when your ball accidentally moves on the putting green, or when applying a rule such as where removing a penalty stake moves your ball. I’ve seen many players walk up to their ball in the fairway and rotate it to see if it is their ball, unless you have marked the ball first, that is a one-stroke penalty.

NCGA

If you hit your ball during a practice swing anywhere but the putting green, you are assessed a one-stroke penalty for moving
your ball in play and you must replace it. If you played it from where it moved to, then you will get the general penalty – two
strokes – for playing from a wrong place.

If your opponent in match play deliberately moves your ball in play your opponent gets one penalty stroke unless he or she is
conceding the stroke. There are a few exceptions and you can read them under Rule 9.5b. 

If your ball hits another person's ball in play your ball is played where it lies and the other person's ball is replaced without
penalty. There is an exception under Rule 11.1. If your ball hits another ball at rest on the putting green and both balls were
on the putting green before the stroke, you get the general penalty – two strokes.
What caused the ball to move and where the ball is on the course all determine what to do next and whether there is a penalty