The caste system is a hierarchy based on purity. Samsara is the cycle of birth and rebirth which all souls undergo. What determines the form into which a soul is born is the law of karma . Karma is the effect of previous deeds and actions carried out in one's previous life on one's next life. An individual's acts or deeds determine the condition and form into which one is reborn in the next life.
Bad karma leads to the accumulation of pap - sin.
The law of karma determines what a soul is born as - if it is as a human being karma also determines the status of the person. This status is marked by the caste into which the person is born. The cycle of rebirth ends with moksha . Moksha is the final liberation from the series of births and deaths, and earthly life. To attain eternal peace, salvation and liberation involves becoming one with brahman, with God.