A commanding officer (or CO) is the term used to refer to an officer in command of a starship, starbase or Federation installation.
Typically, Commanding Officers hold the rank of Captain or Commander, though at times it may be necessary for officers of higher or lower ranks to take command. Regardless of rank, the ship's commanding officer is referred to as 'the Captain'. Ultimately responsible for the ship and crew, the Commanding Officer is the most senior officer aboard a vessel or starbase. S/he is responsible for carrying out the orders of Starfleet, and for representing both Starfleet and the Federation.