What is offside in soccer?
You can't camp behind the last defender waiting for a pass — that's offside. Treat the defense as a moving line: be on the wrong side of it when the ball is played, and your goal doesn't count.
Explain further
The quick rule covers most cases, but here is the full picture. Offside only applies in the attacking half, and only at the instant a teammate plays the ball — not when you receive it. At that moment, at least two defenders (usually the goalkeeper plus one) must be level with or ahead of you. Drift past that last defender and you are offside, and the goal is waved off.
You are never offside in your own half, from a throw-in, corner, or goal kick, or when you are level with the defender. And being offside is not automatically punished — you have to be 'active': going for the ball, blocking the keeper, or otherwise involved. Stand still in an offside spot and ignore the play, and the referee lets it go.
The rule exists to stop 'goal-hanging' — a striker camped by the net waiting for long balls. It forces attackers to time their runs with the defense, which is why forwards sprint forward at the exact second a teammate passes. That split-second timing is the whole art of it.