illustration (attribution, if any possible, is at the end of the article)
The Pāḷi Canon traditionally analyses consciousness in 6 forms: the five senses and the 'discursive' consciousness, the one that 'talks' in our head and manipulates concepts [it is understood that there's still a 'stimulus' for such a consciousness, the concept itself popping up into mind, without us necessarily controlling which one comes up… The concept might arise as a causal consequence from the other types of consciousness, or from thought habits (karma)].
The analysis in 8 consciousnesses —instead of 6— initially comes from the Mind-Only (Yogacara) school, but it is the natural continuation of the 'categorisation' effort started with the Abhidhamma (of the early schools).
If you check the (e.g. Theravada) Abhidhamma, some phenomena are classified as mental factors (e.g. greed), citta or 'mind' is a separate phenomenon (and apparently alone but viññānakicca associates 14 'functions' to it), etc.
These first 6 consciousnesses were not particularly expanded in scope by the Yogacara school, nor analysed much deeper than in the Pāḷi Canon. Ultimately, their nature is dependent on stimuli and the interplay of the five skandas. They are 'reactive' by nature, they are impermanent in the most obvious manner…
But the Yogacara school was much interested in understanding (by analysis and by meditative practices (hence of name of 'yoga')) how phenomena arise out of emptiness.
It simply started from the fact that even when we logically agree with the emptiness of the world, this is still not how we experience it.
The Yogacara thus fully accepted emptiness (and as such was not an attempt to contradict Madhyamaka analysis or other teachings of the Perfection of Wisdom), but it wanted to explore how our mind takes empty phenomena and builds an illusion of permanent inherently-existent things and processes.
By accepting emptiness fully, the Yogacara had difficulty (and interest) to explain a few teachings of the Buddha though, for example karmic continuity.
While karma might be seen as a provisional teaching, the Yogacara still wanted to make sense out of it (again: how does 'karma' come to appear to us —even conventionally,— in spite of its empty nature?).
By focusing so much on the mind, the Yogacara also had to consider the nature of illusions and errors, and how these would arise (but also cease, since the goal remains to achieve Liberation!).
On top of the 5 sense-consciousnesses, Yogacara 'splits' citta into three: the reactive-to-stimulus part (6th), the deluded thoughts (7th), and the 'tendencies' (8th).
Thus, the Yogacara had 2 extra consciousnesses on top of the 6 sense-associated consciousnesses:
• the 7th consciousness has been called the "afflicted mind";
• the 8th consciousness has been called the "store-consciousness".
The store-consciousness (alayavijnana) has been called thus, because it notably 'stores' karmic 'seeds.'
Karmic seeds being empty, one has to be careful with not reifying these. To avoid this risk, it is helpful to remember that the 8th consciousness also receives mental impressions and the 'force of habit.' Anyone studying Yogacara would have understood already how karma relates to habits (and delusions created out of seeing habits as something permanently true: for example, one is violent and gets away with it… hence is born the ignorant delusion that violence is okay… hence one will likely repeat being violent in the future… hence one will certainly meet retribution due to this violence. Karma does not explain everything —other 'natural' laws operate too— but it does explain how an unwholesome act leads to delusion which will lead to 'punishment' or 'reward' by repetition).
The mental activity associated to the 8th consciousness is threefold.
The first and most known function is the maturation of karmic seeds. It is basically the perpetuation of the delusions —good or bad, since karma also deals with meritorious acts— until one becomes less ignorant and finally sees impermanence and suffering and emptiness (even in wholesome acts). The perpetuation lies mostly in a constantly renewed appropriation of cognitions (which evolve, adding or losing nuances, but remain 'distinguishable' as individualised cognitions for a while).
The second function is as a context (i.e. causes and conditions) for the other consciousnesses to exist (i.e. become distinct from).
The third function is in producing cognitions. As suggested above, the maturation of karmic seeds really relates to perpetuating (ignorant) cognitions. Prior to perpetuating them, one needs them to be born…
While the 8th consciousness is a 'support' for the other consciousnesses, it is also the 'receptacle' of what these consciousnesses create. Just like the skandas are not hierarchically ordered (i.e. form leads to feelings, perceptions, ideas and consciousness; but form is also the 'result' of consciousness as without consciousness we would only 'perceive' a chaos of stimuli… consciousness is what makes form arise with a foreground and a background), the eight consciousnesses are not hierarchically ordered, they co-dependently arise.
The 8th consciousness is seen as the only consciousness to 'continue' during deep sleep or coma. It is a subtle process, and obviously should not be reified. To call it a 'consciousness' is already a result of an innate tendency of 'appropriation.' Somehow the sense of 'self' arises from taking experience from the other consciousnesses and 'attributing' these experiences to the 8th consciousness: this 'appropriation' creates a "mine", from which a "me" can arise.
At this point, one may ask 'who' performs the attribution of experience to the 8th consciousness… and we thus highlight a function of the 7th consciousness!
The 7th consciousness is called the defiled consciousness, or the obscuration-consciousness. Interestingly, it is not so much that it creates defilements or obscuration (which are generated from an ignorant response to stimuli) but it 'appropriates' them. The 7th consciousness is what makes my ideas be 'mine.' As such, it is the consciousness creating the biggest delusion of all: the belief in a 'self' (atman).
Interestingly enough, the 8th consciousness also relates to the clear mind of a Buddha (once it no longer generates new karmic seeds, and one as thus ended cyclical existence), it relates to Buddha-nature.
When the 8th consciousness stops generating or even storing karmic seeds, or habits, by definition it becomes free from habits, free from pre-determination, i.e. simply free.
The Yogacara school focuses on exercises to 'purify' the mind. These really address the 7th and 8th consciousnesses mostly, to prevent appropriation and also to stop believing previous delusions. One may note that the act of appropriation requires something (some cognition) to associate to 'someone' (some consciousness), so a favoured way to practice in Yogacara focuses on the purification of the 8th consciousness. When the 8th consciousness stops storing cognitions, it becomes 'transparent' and once it is transparent, even the 7th consciousness cannot grasp it to associate some experience to it!
All the above analysis however would not explain the "nirvana with residue" very easily, so it is a teaching device. Just like Emptiness was a teaching device, not a metaphysical truth.
Karma is tendencies-based, not retribution-based, so the 8th consciousness is often associated with the idea of "karmic seeds" and called the 'store-consciousness'… but karmic 'seeds' are conditioned, impermanent, unsatisfactory and ultimately 'empty' of essence.
The Yogacara school, like any school of Buddhism, should not be clung to: the raft has to be left once the other shore is reached… One has to remember that analysis in Buddhism is to help us enquire into our experience, and get free from fixed thoughts and 'truths,' the description in 8 consciousnesses is not meant to be exhaustive. This will lead for example to a Zen patriarch denying the existence of a mirror to polish… The 8 consciousnesses are empty.
illustration: "deliberation" © Mario Sánchez Nevado (aegis-strife.net)