I resolv'd to faign, that all those things which ever entred into my Minde, were no more true, then the illusions of my dreams. But presently after I observ'd, that whilst I would think that all was false, it must necessarily follow, that I who thought it, must be something. And perceiving that this Truth, I think, therefore, I am, was so firm and certain, that all the most extravagant suppositions of the Scepticks was not able to shake it, I judg'd that I might receive it without scruple for the first principle of the Philosophy I sought.So, in other words, even if everything that you are seeing/hearing/experiencing in life is somehow an illusion, the one thing that an individual can cling to is that the process of thought means that they must exist. Even if life is a series of shadows on the cave wall, the idea of personal identity is the anchor that can see you through.
Descartes goes on to write about how he systematically worked to withhold the common sense belief that the things he could see were really there and the things he could hear were really making sound, etc. The one thing that he could not talk his mind into believing was that he wasn't really there. The idea 'I am not' makes no sense and he couldn't pretend that it did. Whatever else was illusion, that one essential fact could not be a trick.
From this he moves on to a conclusion that is a bit more shaky:
So as it followed, that it must have bin put into me by a Nature which was truly more perfect than I, and even which had in it all the perfections whereof I could have an Idea; to wit (to explain to my self in one word) God.This then is his second foundational statement, that his being implies a more perfect creator. This isn't an uncommon thought though it's widely cast aside in these more modern times. If there were rational beings that were randomly created through evolution and chance, there is no reason to think that they wouldn't suffer the same identity crises and wonder about the origins of their Nature.