Generally, people use can't in speech and informal writing, and cannot or can not in formal writing or very formal speech. Also (as @Kris points out in a comment), cannot might be used when you need to carefully distinguish it from can't in speech.
differences - When to use "cannot" versus "can't"? - English Language ...
As does Thesaurus.com: The terms cannot and can not are identical in meaning and are typically considered to be alternate forms of one another. However, the form cannot is much more commonly used than can not. Cannot has become the standard form in formal writing (and is typically the form recommended by most grammar resources and style guides).
If I am writing a formal letter, should I use "can't," "cannot," or ...
Cannot is the only negative form that contains not rather than -n't. Theoretically, since it is a single word, you can say why cannot you... without a problem. My theory is that modern English speakers don't want to put cannot before the subject because it contains not and sounds like can not.
1 There is no correct way to use "cannot help but." There are two traditional and synonymous idioms, "cannot but [do something]" and "cannot help [doing something]." Those who say "cannot help but" are conflating the two (in much the same some people conflate "irrespective" and "regardless" to create the nonsensical "irregardless").
conditional perfect - Right way to use "Cannot but help" - English ...
The phrase "can not" may mean "cannot" or "can't," but it also may mean "able not to," which is much different than "not able to" as it conveys the ability to not do something rather than the inability to do it.