A player is not penalized simply for standing in an offside position. The offence occurs when a teammate plays or touches the ball and the player becomes involved in active play while in an offside position. The law considers the player's position relative to the ball and the second-last opponent at the relevant moment.
There are important exceptions. A player cannot be offside directly from a goal kick, throw-in or corner kick. Officials also consider whether a player interferes with play, an opponent or gains an advantage from a rebound. The rule is detailed, so close decisions may involve assistant referees and video review where the competition uses it.