Further to previous, the assistant referee remains level with the second rearmost defender for the majority of the time. He/she will only leave this position if the ball is further forward than the second last defender ie. the ball has travelled beyond the defence/attack and is going to the goalkeeper. They do this in case the ball travels over the goalline and therefore they need to be level to see it has crossed completely over the line.
However, as I say for the majority of the time they will stay level with the second rearmost defender. This is because this is the optimum position for judging offsides.
If the assistant is level with the second rearmost and an attacking player is to the right of them, then this attacking player is in an offside position. Then dependant on the other criteria of Law 11, the assistant will decide whether to raise the flag and indicate offside.
It is important to understand that it is not an offence to be in an offside position. It only becomes an offence when they recieve the ball or interfere with an opponent etc.
There will be numerous times during a game when the assistant will 'keep the flag down' allowing play to continue because even though the player is offside, an offence is not being committed
As for how and when to judge offside, studro makes a great point that the body position of the assistant is so important. By being square on to the field of play they have a great view of when the ball is played and also the line of players in front of him. Very little head movement is required as it where.
In England, this movement is known as crabbing and there is a great emphasis on this. Assistant Referees physical training plans usually include some of this sidestep running.
Even being a metre off being level with the second rearmost defender can cause an error in offside judgment. This means when looking across the field of play you do not have a true view of whether a player is offside
The difficulty comes when the ball is on the same side as the assistant just a bit further down the line from him. The assistant is then required to turn his head left to watch the player about to kick the ball and also across the field to study the offside line. Add into this the assistant is watching for any fouling, and the ball crossing the line for a throw in, even a quick glance away from across the field of play (ie. away from the second last defender) can cause you to suddenly be not level any more.
As per previous responses, listening for the ball being kicked is useful and it is surprising that even in grounds with many thousands of people you can still hear the thud of the kick.
A trick used in the english game is for the other assistant or referee to help the assistant by using the communication kit and tell him that the ball has been played forward. This means the assistant can keep watching the line and know the ball has been played forward.
Additionally the assistant will do similar on a throw in deep in the referees half. Rather than have the referee watch the throw (and take his eyes away from the players), he can watch the players and the assistant will say "In play". This means should the referee notice any pushing, if he blows his whistle, he will know if the ball was in play or not. If the ball was in play he would need to award a freekick. If not in play then he could say "calm down fellas" before allowing the throw in.