It depends on what moved it. If wind or water moved your ball, you play it from its new spot with no penalty. If you caused it to move, you replace it and usually add one penalty stroke. If someone or something else moved it, you replace it with no penalty.
The ball moved by itself, from wind or water
No penalty. Play it from where it comes to rest. If it was on the putting green and you had already lifted and replaced it, it goes back on its original spot, whatever moved it.
You moved it
If you lift your ball, deliberately touch it, or cause it to move, you replace it on its original spot (estimate the spot if you don't know it) and add one penalty stroke. There are exceptions where there is no penalty:
- You were searching for or identifying the ball.
- You were on the putting green and moved it by accident, however it happened.
- You were taking a reasonable action under a Rule, such as marking and lifting the ball, removing a movable obstruction, or measuring for relief.
- You were taking relief or lifting the ball under a Rule that tells you to.
Someone else moved it
If you're in match play and your opponent moves your ball, they get a penalty stroke in most cases and you replace it. If another player, an animal, or a ball in motion moves it and that is known or virtually certain, you replace it with no penalty. In stroke play, another player counts as an outside influence.
What if I can't tell what moved it?
Your ball is treated as having moved only if you know or are virtually certain that it did. If it is not clear what caused it, treat it as moved by natural forces and play it from where it is.
What if it moves during my swing?
If it starts moving after you've begun the backswing and you go ahead and hit, you don't replace it. You play it from where it ends up.
The governing rule is Rule 9.
Local rules
Your league's committee may have local rules that change this. Ask the organizer which ones your league uses.