The Marxist theory of ideology — how social ideas and social consciousness arise from the material conditions of life — can be found in such early works as The German Ideology (1845) , The Eighteenth Brumaire of Louis Bonaparte (1852) and Marx’s Contribution to a Critique of Political Economy (1859). All these can be found at marxists.org.
One crucial text is from The German Ideology:
“The ideas of the ruling class are in every epoch the ruling ideas, i.e. the class which is the ruling material force of society, is at the same time its ruling intellectual force. The class which has the means of material production at its disposal, has control at the same time over the means of mental production, so that thereby, generally speaking, the ideas of those who lack the means of mental production are subject to it. The ruling ideas are nothing more than the ideal expression of the dominant material relationships, the dominant material relationships grasped as ideas; hence of the relationships which make the one class the ruling one, therefore, the ideas of its dominance. The individuals composing the ruling class possess among other things consciousness, and therefore think. Insofar, therefore, as they rule as a class and determine the extent and compass of an epoch, it is self-evident that they do this in its whole range, hence among other things rule also as thinkers, as producers of ideas, and regulate the production and distribution of the ideas of their age: thus their ideas are the ruling ideas of the epoch. For instance, in an age and in a country where royal power, aristocracy, and bourgeoisie are contending for mastery and where, therefore, mastery is shared, the doctrine of the separation of powers proves to be the dominant idea and is expressed as an “eternal law.”
“The division of labour, which we already saw above as one of the chief forces of history up till now, manifests itself also in the ruling class as the division of mental and material labour, so that inside this class one part appears as the thinkers of the class (its active, conceptive ideologists, who make the perfecting of the illusion of the class about itself their chief source of livelihood), while the others’ attitude to these ideas and illusions is more passive and receptive, because they are in reality the active members of this class and have less time to make up illusions and ideas about themselves. Within this class this cleavage can even develop into a certain opposition and hostility between the two parts, which, however, in the case of a practical collision, in which the class itself is endangered, automatically comes to nothing, in which case there also vanishes the semblance that the ruling ideas were not the ideas of the ruling class and had a power distinct from the power of this class. The existence of revolutionary ideas in a particular period presupposes the existence of a revolutionary class; about the premises for the latter sufficient has already been said above.
“If now in considering the course of history we detach the ideas of the ruling class from the ruling class itself and attribute to them an independent existence, if we confine ourselves to saying that these or those ideas were dominant at a given time, without bothering ourselves about the conditions of production and the producers of these ideas, if we thus ignore the individuals and world conditions which are the source of the ideas, we can say, for instance, that during the time that the aristocracy was dominant, the concepts honour, loyalty, etc. were dominant, during the dominance of the bourgeoisie the concepts freedom, equality, etc. The ruling class itself on the whole imagines this to be so. This conception of history, which is common to all historians, particularly since the eighteenth century, will necessarily come up against the phenomenon that increasingly abstract ideas hold sway, i.e. ideas which increasingly take on the form of universality. For each new class which puts itself in the place of one ruling before it, is compelled, merely in order to carry through its aim, to represent its interest as the common interest of all the members of society, that is, expressed in ideal form: it has to give its ideas the form of universality, and represent them as the only rational, universally valid ones. The class making a revolution appears from the very start, if only because it is opposed to a class, not as a class but as the representative of the whole of society; it appears as the whole mass of society confronting the one ruling class.”