What makes the offside rule especially complicated is that a player can be in an "offside position" without being offside. Two things are necessary to be "offside":
1st - The player must be in an "offside position" at the moment the ball is "played" by a teammate. To be in an "offside position", a player must be on the opponent's half of the field & closer to the opponent's goal line than both the ball & the second-last defender. A player is not in an offside position if he is on his own half of the field (i.e. the half his goalkeeper is on), or even with the second-to-last defender or the last 2 defenders. (The goalkeeper is usually the last defender, or one of the last two, but he might not be; the rules just refer to the last 2 defenders & don't mention the goalkeeper). This is often difficult to call. (For example, if a player is even with the Second Last Defender & thereby in an "onside position" but runs past the Second Last Defender a split second after his teammate makes a through pass. In this example, the player is not offside because he was in an onside position at the moment the ball was played.)
2nd - The player must be involved in "active play" by either:
-gaining an advantage by being in an offside position, or
-interfering with play, or
-interfering with an opponent
For example, if a player is in an "offside position" but not involved in the play, he would not be "offside". This can be a tough call & can be very judgmental. For example, what if the "onball attacker" is to the right of the goal but a teammate is in an "offside position" to the left of the goal? You can argue that the teammate wasn't involved in the play, but you can also argue that he distracted the goalkeeper because the goalkeeper had to worry about the possibility of a crossing pass & therefore the attacking team "gained an advantage by being in an offside position", in which case the teammate was "offside". In this case, the Referee's decision might depend on whether he felt the Goalkeeper was influenced by the player in the offside position. Obviously, it is a very subjective decision.
Special Cases Where Offside Is Not Called: A player is not offside if he receives the ball directly from a goal kick, throw-in or corner kick, even if he is in an offside position; however, once touched, the offside rule starts and if it is then played to a player in an "offside position", offside may be called. (Note that the offside rule does apply on "free kicks"). A player is also not offside if he passes the ball backward, even if doing so leaves him in an "offside position". However, if he is in an offside position & the ball is played back to him (e.g., a wall pass), then he can be called offside.