Offside is the rule that generates more sideline arguments than any other in soccer. Here is the actual rule, written for someone who does not have a referee license.
The basic requirement: to be offside, a player must be in the opponent’s half of the field, and they must be nearer to the opponent’s goal line than both the ball and the second-to-last defender at the exact moment the ball is played by a teammate.
The second-to-last defender part is the piece that trips people up. The last defender is almost always the goalkeeper. The second-to-last is the last field player.
So a forward is onside as long as they are level with or behind that second-to-last defender when the ball is kicked to them.
The timing part: the player’s position is judged at the moment the ball is played, not at the moment they receive it. A player can be behind the last defender when the ball is kicked, sprint into an offside position, and receive the ball there without a call. What matters is where they were when the ball left the kicker’s foot.
When offside cannot be called: on a throw-in, corner kick, or goal kick. These are restarts, and offside does not apply. Also, a player in their own half cannot be offside regardless of their position relative to defenders.
What you will see on the field: the assistant referee (linesperson) runs the line with the flag ready. When they judge a player to be offside, they raise the flag and the referee stops play. The other team gets an indirect free kick from where the offside player was when they received the ball.
The honest disclaimer: at youth levels under age 12, many leagues do not enforce offside strictly, or waive it entirely, to let players focus on other skills. If your 8-year-old was called offside and you are confused about it, the youth program may be experimenting with partial enforcement.
Ask the coach what the league rules are. The answer varies