In football, a player is in an offside position if "he is nearer to his opponents' goal line than both the ball and the second to last opponent," unless he is in his own half of the field of play. A football player level with the second to last opponent is not in an offside position.
In 2005 The International Football Association Board agreed a new Decision in Law 11 that being 'nearer to his opponent's goal line' meant that "any part of his head, body or feet is nearer to his opponents' goal line than both the ball and the second last opponent. The arms are not included in this definition."
This is taken to mean that any part of the attacking player named in this Decision 2 has to be past the part of the second last defender closest to his goal line (excluding the arms) or past the part of the ball closest to the defenders' goal line.
In general, what this means is that either the attacking football team should ensure the opposing team has at least two players (of which the opposition's goalkeeper is included) in between the goal line and the nearest player of the attacking team, or all football players of the attacking team should be behind the ball such that it remains closer to the goal line than any of the player of the attacking team. If the goalkeeper is ahead of the play, then the forward will have to be in line with or behind two defenders (considering they are not in their own half).
It's also worth noticing that if two football players of the attacking team only have one defender (typically the goalkeeper) between them and the goal, it is allowed for them to pass the ball between each other, as long as the player passing the ball is ahead of the player receiving it because the ball is nearer to the goal line than the receiver so he is not at an offside position.
A football player in an offside position is only committing an offside offence if, in the opinion of the referee, he is involved in active play "at the moment the ball touches or is played by one of his team." A player is not committing an offside offence if the player receives the ball directly from a throw-in, goal kick or corner kick.
In order for an offside offence to occur in football, the player must be in an offside position when the ball is touched or played by a team-mate; a player who runs from an onside position into an offside position after the ball was touched or played by a team-mate is not penalised.
Conversely, a football player who is in an offside position when the ball is touched or played by a team-mate may potentially commit an offside offence even if they run back in to an on-side position before receiving the ball. This potential remains until a teammate again touches or plays the ball and offside position is reevaluated, or the ball goes out of play, or an opponent makes a controlled play on the ball. A player formerly in offside position who benefits from an ill-advised but deliberate play by an opponent is not judged offside.
* Interfering with play means playing or touching the ball passed or touched by a teammate.
* Interfering with an opponent means preventing an opponent from playing or being able to play the ball by clearly obstructing the opponent's line of vision or movements or making a gesture or movement which, in the opinion of the referee, deceives or distracts an opponent.
* Gaining an advantage by being in an offside position includes playing a ball that rebounds to the player off a post or crossbar or playing a ball that rebounds to the player off an opponent having been in an offside position.
In practice, a player in an offside position may be penalised before playing or touching the ball if, in the opinion of the referee, no other team-mate in an onside position has the opportunity to play the ball.
The football referees' interpretations of these new definitions are rarely controversial. When it does happen, it is largely over what movements a player in an offside position can make without being judged to be interfering with an opponent. The famous quote: "If he's not interfering with play then what's he doing on the pitch?" is attributed by some to Bill Nicholson.
The sanction for an offside offence is an indirect free kick to the opposing football team, at the spot where the offence occurred. Most referees use their discretion and let play go on if the "offended" team already has the advantage or ball, in order not to slow down play with redundant free kicks that achieve the same purpose of giving the advantage or ball back to the "offended" team. This discretion should not be confused with the advantage clause, which can only be applied to Law 12. In essence, the referee who doesn't whistle offside must be judging that one of the elements of offside was not present.