The Essay Concerning Human Understanding is sectioned into four books. Taken together, they comprise an extremely long and detailed theory of knowledge starting from the very basics and building up. Book I, "Of Innate Ideas," is an attack on the Cartesian view of knowledge, which holds that human beings are born with certain ideas already in their mind. "Of Innate Ideas" begins with an argument against the possibility of innate propositional knowledge (that is, innate knowledge of fact, such as the fact that whatever is, is), and then moves on to an argument against the possibility of innate ideas (such as the idea of God).
Once he feels secure that he has sufficiently argued the Cartesian position, Locke begins to construct his own theory of the origins of knowledge. The short answer is: from experience. The long answer is Book II. Book II lays out Locke's theory of ideas. He argues that everything in our mind is an idea, and that all ideas take one of two routes to arrive in our mind: either they come in through the senses, or else they come in through the mind's reflection on its own operation. He also classifies our ideas into two basic types, simple and complex (with simple ideas being the building blocks of complex ideas), and then further classifies these basic types into more specific subcategories. The vast majority of this book is spent analyzing the specific subcategories of our ideas.
Though Book II is primarily an attempt to account for the origin of all our ideas, it also includes two other very important discussions, only tangentially related to the subject of the origin of ideas. Chapter VIII contains Locke's argument for a distinction between primary and secondary qualities. He attempts to show that there are two very different sorts of relations that can hold between the qualities of the outside world and our ideas about those qualities. The relation between primary qualities (e.g. size and shape) and our ideas of them is one of resemblance; what we sense is roughly what is out there. In contrast, the relation between secondary qualities (e.g. color and odor) and our ideas of them is one of mismatch; there is nothing out in the world that resembles our sensations. In chapter XXIII, Locke tries to give an account of substance that allows most of our intuitions without conceding anything objectionable.
In Book III, "Of Words," Locke turns from philosophy of mind to philosophy of language. Ideas, however, are still an important part of the picture. According to the theory of meaning that Locke presents, words do not refer to things in the external world but to the ideas in our heads. Locke, relying heavily on his theory of ideas, attempts to give an account of how we form general terms from a world of particular objects, which leads him into a lengthy discussion of the ontology of types (that is, the question of whether there are any natural kinds out in the world or whether all classifications are purely conventional).
Book IV, "Of Knowledge and Opinion," finally gives us the long awaited theory of knowledge. Locke begins with a strict definition of knowledge, one which renders most sciences (all but mathematics and morality) ineligible. Knowledge, according to Locke, is the perception of strong internal relations that hold among the ideas themselves, without any reference to the external world. He lists four sorts of relations between ideas that would count as knowledge (identity/diversity, relation, coexistence, actual existence), and then distinguishes between three grades of knowledge (intuition as the highest, demonstration as a middling level, and sensitive knowledge as a sort of pseudo- knowledge). The remainder of the book is spent discussing opinion or belief, which is the best we can hope for from nearly all our intellectual endeavors.
Locke is very careful to refrain from speaking as if opinion is "mere opinion;" he is not a skeptic and does not believe that science is futile. On the contrary, he is very eager to claim in the last chapters of theEssay, that we should be satisfied with this level of certitude and that we should continue collecting scientific data with gusto. Gaining a better and better opinion of the world is a worthy goal, and one that he shares. He does ask, however, that we be aware that as good as our opinions become, they are never going to reach the level of knowledge.