The offside rule in soccer is both difficult to understand and difficult to enforce. Hence, its widespread unpopularity. I believe, however, that it is a good rule worth keeping in the game. Let me try first to explain the rule clearly to you and then tell you why I believe it is a good rule.
A player for the team with possession of the ball will be judged offside when it is determined (usually by the side judge in his half of the field) that the ball has been played to him (or her - soccer is played wonderfully well by girls and women) by a team mate at a moment he is positioned behind the back-most player on the defensive team. Additionally, the defending team's goalkeeper must also be behind him. Stated in the obverse, a player will be judged onside when the ball has been played to him at a moment he is positioned in front of at least one player on the defensive team and the defensive team's goalkeeper.
(There is also the notion of "passive" offsides, but we will leave that to be answered at another time.)
There are three important exceptions to offside rule in soccer. One: a player can never be ruled offside in his own defensive end. Two: an inbound throw from the touchline (or sideline) is not subject to the offside rule. Three: a ball played from a defender to an offensive player nominally offside does not put the offensive player into an offside position.
No doubt this explanation would be more easily made and understood if I had recourse to a diagram. Still, if you can keep it in mind while you watch the game soon enough it will come clear to you.
The offside rule in soccer has virtuous implications for both offensive and defensive play.
In the first instance: the offensive team is essentially prohibited from what we used to call "cherry picking." That is, they cannot simply park a forward player in the defensive end and wait for the opportunity to play a ball to him after it comes into their possession. No, they must develop scoring opportunities moving forward more as a unit. This encourages, even necessitates, sequences of short passing to move the ball upfield and towards the opponents goal. Such play at its most highly developed is fundamental to what we call the "beautiful game."
In the second instance: the defensive team is enabled to play a unified defensive scheme that "compacts" the field. That is, they are able to take the relatively large surface area of a soccer field - often 120 yards long by 75 yards wide - and convert it into a smaller area more easily managed by 11 men for defensive purposes. Again, the result is to require a higher level of ball movement skill by the offensive team resulting in a more entertaining game for the spectator.
Still, the defensive team must always be alert to the exceptions to the rule. All three exceptions prevent overly negative play by the defenders through the introduction of risk. Both the second and third exceptions, as stated above, can arise anywhere on the field at any moment and defenders can only risk trying to compact the field if they can play with great awareness, unity and discipline. The spectator can again be rewarded by the rule as the result of breaking down of a compacted field can be a sudden and spectacular run onto goal for a scoring opportunity.
Thank you for a chance to address this question about the offside rule in soccer. I hope I have illuminated the subject for you and enhanced your appreciation of the game.