The Executive Officer is the second in command of a vessel, starbase or installation.
The XO, as it is abbreviated reports directly to the Commanding Officer(CO).
The primary role of the XO, is as the office of the executive. Both within corporation and the military, the XOs role is a heavily administrative one, involving much liaising and a lot of paperwork. Within the world of Starfleet, the XO is directly responsible for the welfare and performance of the crew.
As part of this role, the XO has to maintain order and discipline of his/her subordinates, is responsible for recommending and organizing promotion, and for recognizing when a crew member may need training or assistance.
Secondary roles are usually more administrative. Conducting the day to day running of an installation or vessel is the role most observed. Liaising with department heads and addressing their needs is also a big part of the XO's job. An old military term says that 'The captain shall only be disturbed with matters of the utmost importance... I decide that importance' On smaller vessels, the Office of the executive may only contain a handful of crew, meaning the officer can then hold secondary duties elsewhere. On board a starship, the XO is usually tasked with his/her primary role and on bigger installations, may be required to perform secondary tasks such as command of an outpost or support ship. To offer an unbiased view and to show co-operation, sometimes an XO can be recruited outside of the traditional routes.
On smaller vessels where fewer crew are required to operate, the XO can be any rank, usually a lieutenant. On larger vessels and some outposts, the XO requires more experience to operate. Ranks from Lieutenant Commander through Captain are seen, though a full Commander is the most common. Major starbases and headquarters that are flagged, usually by an Admiral; will request an Executive Officer capable of command to complete the day-to-day running of the installation. These are very rarely less than a full Commander. A more traditional role may also apply to this individual, as Attaché to the Flag.