Leg before wicket is one of the ways of getting out in cricket. It might be confusing while watching, but the rule is simple when it is familiarized in detail.
There are 3 stumps that are responsible for a wicket.
Off stump, Middle stump and Leg stump.
From a bowler's perspective, Off stump is to the left of Middle stump and Leg stump is to the right of Middle stump.
The above condition is reversed when the batsman is left-handed.
The Batsman is not out,
If the bowler bowls a no-ball.
If the ball pitches outside the line of leg stump, regardless of whether it would have hit the stumps or not.
If the ball hits the bat before striking the pad.
If the ball hits the pad outside the line of off stump after batman's genuine attempt to hit the ball.
The Batsman is out,
If the batsman is struck on the pad in front of the stumps and the ball has pitched in line with the stumps or outside the line of off stump.
If the batsman is struck on the pad outside the line of off stump, without making a genuine attempt to hit the ball.
If the batsman is playing no stroke, even if the ball pitches outside the line of off stump - the batsman is out as long as the ball has gone for the stumps. The batsman is still out even if the ball has not hit their pads or hit on the helmet.
The umpire must also consider four other elements:
The height of the ball's bounce.
swing and spin of the ball.
Where the ball hit the pad.
Whether the batsman is attempting to play a stroke.
LBW appeals happen in few seconds. The umpire has to consider numerous factors before giving the decision. The amount of pressure on the umpire is reduced with the increasing role of technology where a third umpire can decide by watching the shot from various angles.