The one sentence version
You cannot be nearer to the opponents' goal than the ball and the second-last defender at the moment a teammate plays the ball to you.
In practice the second-last defender is almost always the last outfield player, because the goalkeeper is usually the very last. So the shorthand most people use is that you must not be behind the last defender when the pass is played.
The two things people get wrong
First, the position is judged at the moment the ball is played, not at the moment it is received. A player can be miles beyond the defence when the ball reaches them and still be onside, because they were level when the pass was struck. This is what running timing means.
Second, being in an offside position is not itself an offence. You are only penalised if you become involved in the play: touching the ball, blocking an opponent, or obstructing the goalkeeper's line of sight. A player standing offside and jogging away from the action is not penalised.
Why it exists at all
Without it, a team could leave one player permanently standing beside the opposition goalkeeper waiting for a long ball. The rule forces attackers to stay connected to the rest of their team and it is the reason defences push forward together in a line.
It is also the reason goals are now reviewed by video for margins of a few centimetres, which is a genuine and ongoing argument about whether the rule is being applied in the spirit it was written.
If you follow U.S. sportThe nearest idea is an offsides line in hockey, except the line is not painted on the ice, it moves constantly, and it is wherever the second-last defender happens to be standing.