Niyama (Sanskrit: नियम) are positive duties or observances. In Indian traditions, particularly Yoga, niyamas and its complement, Yamas, are recommended activities and habits for healthy living, spiritual enlightenment and liberated state of existence. It has multiple meanings depending on context in Hinduism. In Buddhism, the term extends to the determinations of nature, as in the Buddhist niyama dhammas.
Virtues are extensively discussed in various ancient and medieval era texts of Hinduism. In its Yoga school, they are described in first two of eight limbs (steps, branches, components). The first limb is called yamas, which include virtuous self-restraints (the "don'ts"). The second limb is called niyamas which include virtuous habits, behaviors and observances (the "dos"). These virtues and ethical premises are considered in Hinduism as necessary for an individual to achieve a self-realized, enlightened, liberated state of existence (moksha).
In the diverse traditions and historical debate within Hinduism, some texts suggest a different and expanded list of niyamas. For example, the Shandilya and Varuha Upanishads, the Hatha Yoga Pradipika, verses 552 to 557 in Book 3 of the Tirumandhiram of Tirumular suggest ten niyamas, in the sense of positive duties, desirable behaviors and discipline. The Hatha Yoga Pradipika lists the ten niyamas in the following order, in verse 1.18,
Some texts replace the last niyama of Huta with Vrata. The niyama of Vrata means making and keeping one's vows (resolutions), which may be pious observances. For example, a promise to fast and visit a pilgrimage site is a form of Vrata. The education process in ancient India, where Vedas and Upanishads were memorized and transmitted across generations without ever being written down, required a series of Vrata niyamas over a number of years.
At least sixty five (65) ancient and medieval era Indian texts are known so far that discuss Niyamas and Yamas. Most are in Sanskrit, but some are in regional Indian languages of Hindus. The number of Niyamas mentioned in these texts range from just one to eleven, however 5 and 10 are the most common. The order of listed niyamas, the names and nature of each niyama, as well as the relative emphasis vary between the texts. For example, Sriprashna Samhita discusses only one Niyama in verse 3.22, and that Niyama being Ahimsa. Shivayoga Dipika, Sharada Tilaka, Vasishtha Samhita, Yoga Kalpalatika, Yajnavalkya Smriti and many others, each discuss ten Niyamas. Bhagavata Purana discusses eleven Niyamas, with kind hospitality of guests, to one's best ability, as an additional virtuous behavior. Other texts substitute one or more different concepts in their list of Niyamas. For example, in the five Niyamas listed by Markandeya Purana in verse 36.17, Matanga Parameshvaram in verse 17.31 and Pashupata Sutra in verse 1.9, each suggest Akrodha (non-anger) as a Niyama.
Some yamas (restraints, the "don'ts") are understood as reverse of niyamas (attitudes, behaviors, the "dos") in Hatha Yoga Pradipika. For example, Ahimsa and Mitahara are called as yama as well as niyama in verse 1.17 and 1.40. The text calls Ahimsa (nonviolence and non-injuring anyone by one's actions, words or in thoughts) as the highest virtuous habit, Mitahara (moderation in one's eating and drinking habits) as the best personal restraint, and Siddhasana as the foremost of Asanas in verse 1.40.
In Buddhist commentary (from the 5th to 13th centuries CE) we find the pañcavidha niyama, fivefold niyama which occurs in the following texts:
In these texts the fivefold niyama was introduced into commentarial discussions not to illustrate that the universe was intrinsically ethical but as a list that demonstrated the universal scope of paṭicca-samuppāda. The original purpose of expounding fivefold niyama was, according to Ledi Sayadaw, neither to promote or to demote the law of karma, but to show the scope of natural law as an alternative to the claims of theism.
C.A.F. Rhys Davids was the first western scholar to draw attention to the list of pañcavidha niyama, in her little book of 1912 entitled simply Buddhism. Her reason for mentioning it was to emphasise how for Buddhism we exist in a "moral universe" in which actions lead to just consequences according to a natural moral order, a situation she calls a "cosmodicy" in contrast with the Christian theodicy.:
This is similar to the scheme proposed by Ledi Sayadaw. Western Buddhist Sangharakshita has taken up Mrs Rhys Davids conception of the niyamas and made it an important aspect of his own teachings on Buddhism. 
In Pāli the word is spelled both niyama and niyāma, and the Pali Text Society Dictionary says that the two forms have become confused. It is likely that niyāma is from a causative form of the verb ni√i.