A player is in an offside position if any part of their head, body or feet is closer to the opponents' goal line than both the ball and the second-last opponent. Hands and arms do not count.
Position is not an offence
Being in that position is not punished by itself. The player is penalised only if they become involved in play when a teammate passes or touches the ball, for example by receiving it or interfering with an opponent.
When offside cannot happen
There is no offside from a goal kick, a throw-in or a corner kick. A player also cannot be offside in their own half. When a defender plays the ball deliberately, the situation is judged again.
Video review now checks close calls, which is why you often see a long wait before a goal is confirmed.