The pips ranking system on “Star Trek” wasn’t adopted until the days of “Next Generation,” but they are the clearest, so it’s a good place to start when educating one’s self on Starfleet’s chain of command.
Petty officers wear one empty pip on a starship. These are the enlisted members who didn’t attend Starfleet Academy. Engineers, security personnel, yeomen, and the like are petty officers and take orders from the lowest-ranking Academy graduate officers on the ship. If one looks into expanded universe lore, one can find a hierarchy of Starfleet petty officers. There are master petty officers at the top, chief petty officers directly underneath, and several ranks below them. Those ranks, however, are rarely discussed on “Star Trek.”
As mentioned above, ensigns wear one full pip, as seen on Wesley Crusher’s collar above. Lieutenants junior grade wear one full pip and one empty pip. Lieutenants wear two full pips, and lieutenant commanders wear two full pips and one empty pip.
Commanders wear three pips, because it is a difficult rank to achieve.
Captains wear four pips, and are typically given the promotion when they are put in command of a starship. It’s understood that only one captain lives on a starship at any given time.
Admirals have their own ranking system, with solid pips surrounded by boxes.
Commodores (an honorary title) have one boxed pip, rear admirals have two, vice admirals have three, regular admirals have four, and fleet admirals have five. “Star Trek” only deals with admirals from time to time, however, and characters who achieve that rank are often presented as villainous or unduly ambitious; Trekkies have been trained to be suspicious of admirals.