There are, as you say, two formulations of the categorical imperative. The first has to do with the motives for a person's actions. Here, Kant says that the categorical imperative is the rule that one must

Act only according to that maxim by which you can at the same time will that it should become a universal law.

In other words, you need to look at the rule that you are following when you act. If you could accept that rule being a universal rule for all people, then your act is moral.

The second formulation of the categorical imperative refers to the people affected by one's actions. It says that you must

Act so that you treat humanity, whether in your own person or in that of another, always as an end and never as a means only.

This means that you must never treat any human (or group of humans) as a simple tool. You must always treat them as if they matter for their own sake rather than for the sake of whatever good they can do for you.