In open play, players are offside if they are either in front of a team mate who is carrying the ball, or in front of a team mate who has kicked the ball. Offside players cannot participate in any further part of the game until they become onside again. If offside players do participate in the game, for example by playing the ball or obstructing an opponent (by loitering) then their team will be penalised.
In any other part of play (scrums, rucks, mauls or line outs), players are offside if they are in front of the off-side line. This is an imaginary line parallel to the goals which runs through the hindmost foot of the hindmost player in the ruck/maul/scrum. Any players joining a ruck/maul or scrum from in front of the off-side line is offside and their team will be penalised.