In the fourth book of his Essay Locke applies the results of the earlier books to determine the nature and extent of knowledge. As ideas are the sole immediate objects of the mind, knowledge can be nothing else than "the perception of the connexion of and agreement, or disagreement and repugnancy, or any of our ideas." This agreement or disagreement is said to be of four sorts: identity or diversity; relation; co-existence or necessary connection; real existence. Each of these kinds of knowledge raises its own questions; but, broadly speaking, one distinction may be taken as fundamental. In the same paragraph in which he restricts knowledge to the agreement or disagreement of our ideas, he admits one kind of knowledge which goes beyond the ideas themselves to the significance which they have for real existence. When the reference does not go beyond the ideas "in the mind," the problems that arise are of one order; when there is a further reference to real things, another problem arises.
Locke also distinguishes between two degrees of knowledge: intuition and demonstration. In the former case, the agreement or disagreement is immediately perceived; in the latter, it is perceived through the mediation of a third idea, but each step in the demonstration is itself an intuition, the agreement or disagreement between the two ideas compared being immediately perceived. He believes that mathematics and ethics are demonstrable. When ideas are together in the mind, we can discover their relation to one another; so long as they are not taken to represent archetypes outside the mind, there is no obstacle to certainty of knowledge. "All relation terminates in, and is ultimately founded on, those simple ideas we have got from sensation or reflection" (Bk. 2:28:18). but "general and certain truths, are only founded in the habitudes and relations of abstract ideas" (Bk. 4:12:7). In this way Locke vindicates the certainty of mathematics: although instructive, the science is merely idea, and its propositions do not hold of things outside the mind. He thinks also that "morality is capable of demonstration as well as mathematics." But, in spite of the request of his friend Molyneux, he never set out his ethic doctrine in detail. In Book II he reduced moral good and evil to pleasure and pain which -- as reward and punishment -- come to us from some lawgiver; thus they point to a source outside the mind. But his ground for maintaining the demonstrative character of morality is that moral ideas are "mixed modes," and therefore mental products, so that their "precise real essence ... may be perfectly known." He ventures upon two examples only of this demonstrative morality; and neither of them is more than verbal or gives any information about good or evil. Yet the doctrine is significant as showing the influence upon Locke of another type of demonstrative thought.
Thus, knowledge of mathematics and ethics may be firmly establish, particularly as these subjects involve relations between ideas, and thus make no claims about matters of real existence. When it comes to knowledge of real existence, though, ultimately there are only two certainties: the existence of ourselves (by intuition) and that of God (by demonstration).
Concerning the self, Locke agrees with Descartes that the existence of the self is implied in every state of consciousness. Every element of our experience, every idea of which we are conscious, is a certificate of our own existence, as the subject of that experience:
As for our own existence, we perceive it so plainly and so certainly, that it neither needs nor is capable of any proof. For nothing can be more evident to us than our own existence. I think, I reason, I feel pleasure and pain: can any of these be more evident to em than my own existence? If I doubt of all other things, that very doubt makes me perceive my own existence, and will not suffer me to doubt of that. For if I know I feel pain, it is evident I have as certain perception of my own existence, as of the pain I feel: or if I know I doubt, I have ascertain perception of the existence of the thing doubting, as of that thought which I call doubt.
However, Locke fails to point out how the self can be an idea and thus belong to the material of knowledge. An idea of the self cannot come from sensation; and the simple ideas of reflection are all of mental operations, and not of the subject or agent of these operations. On the other hand, when he had occasion to discuss personal identity, he followed his new way of idea, and made it depend on memory.
Concerning God's existence, his proof is a cosmological-type argument. From the certainty of our own existence that of the existence of God immediately follows. A person knows intuitively that he is "something that actually exists." Next a person knows with intuitive certainty, that "bare nothing can no more produce any real being, than it can be equal to two right angles." it is, therefore, "an evident demonstration, that from eternity there has been something. And since all the powers of all beings must be traced to this eternal Being, it follows that it is the most powerful, as well as the most knowing, that is, God. Eternal ind alone can produce "thinking, perceiving beings, such as we find ourselves to be" (Bk. 4:10). Locke here assumes, without question, the validity of the causal principle even beyond the range of possible experience.