Relevant SE link: "I think, therefore I am" - How does "I" establish "I" before "I" can "think"?
how does one know that one thinks?
Because something that doesn't exist can't think. Therefore you must exist (or rather I must exist, as I can't say anything about you beyond what my senses tell me is the case). If I didn't exist, then I couldn't be thinking. It is an absolute incoherent statement to say that I can think and not exist at the same time. We can't even begin to try to give a rational argument to justify such a position.
What form I exist isn't really knowable with certainty. Am I part of a dream? Maybe. Or perhaps I am a brain in a vat or in a supercomputer simulation of our universe, and my essence consists of nothing more than binary coding. Entirely possible.
What Descartes wanted to do with The Cogito was to start with a foundational philosophy rooted in the certainty he saw in self-doubt. Using it as an edifice to establish the rest of his philosophy. A lot of it was supported by the Christian God not being an "evil deceiver" tricking him into believing he was experiencing what he was experiencing through his perceptual apparatus.
Reference:
Brueckner, Tony, "Skepticism and Content Externalism", The Stanford Encyclopedia of Philosophy (Winter 2016 Edition), Edward N. Zalta (ed.), URL = https://plato.stanford.edu/archives/win2016/entries/skepticism-content-externalism/.