A commanding officer (or CO) is a term used to describe one's rank in relation to others within the same environment.
One meaning of commanding officer is the highest-ranking officer and commander of a unit. On starships, the CO usually has the rank of captain, though sometimes a commodore or fleet captain may also hold this position. On starbases, the CO is sometimes referred to as "portmaster" and was usually a flag officer. Some bases, however, are commanded by captains or commanders.
On starships, it is general practice to address the commanding officer as "Captain," regardless of their actual rank or position.
In general, commanding officers are dressed in the colors of the command division, but there are some exceptions in Starfleet uniform usage.
In rare occasions, the commanding officer need not be a ranking officer, especially in dire circumstances.
The term "commanding officer" can also be used to refer to the officer whom one directly reports to in the chain of command or in a department. Occasionally, it simply identifies an officer of higher rank in comparison to another, or the officer with the most experience if more than one officer holds the highest rank at the time, although this is usually referred to as a ranking officer.