Most moral advice is conditional. Do not lie, because you will be caught. Be generous, because people will like you. Kant thought all of that missed morality entirely: those are instructions for getting what you want, and if you stopped wanting it the instruction would evaporate. A genuine moral requirement holds regardless of what you happen to want. That is what "categorical" means.
The test itself is a consistency check. Before acting, state the rule you would actually be acting on — your maxim. Then ask whether you could will that rule to hold universally, for everyone, always. If universalising it produces a contradiction, the act is forbidden. Kant's own example is the lying promise. Consider making a promise you intend to break. Universalise it: everyone makes promises they intend to break. The institution of promising collapses, because no one would believe a promise — and with it collapses the very practice your maxim depended on. The maxim destroys its own conditions. That is not bad strategy; it is incoherence.
Kant gave several formulations he considered equivalent. The second is the most quoted: treat humanity, whether in yourself or another, always as an end and never merely as a means. Note the word "merely" — you use the barista as a means to coffee, which is fine, so long as you do not treat them as nothing but a tool. Deceiving or coercing someone violates this, because it routes around their capacity to decide for themselves. A third formulation asks you to act as a legislating member of a "kingdom of ends," a community of rational agents each of whom sets the laws all are bound by.
The objections are serious and well known. The rigorism problem: Kant appears committed to telling the truth even to a murderer asking where your friend is hiding, which strikes most people as monstrous. The maxim-description problem: results depend on how you phrase your rule, and a sufficiently specific phrasing can universalise almost anything. And critics from the consequentialist tradition argue that a theory indifferent to outcomes is indifferent to suffering. Kantians have replies to each, but the disagreement with utilitarianism it provokes is one of the deepest live divides in ethics.