A Captain is generally the commander of a single 'unit' in whatever service he serves in. In pre-industrial militaries a Captain might command a column of soldiers or a single sailing ship, both relatively equal posts in terms of human lives under one's control. However, as militaries developed the ship got bigger and the Captain stayed in command. Bigger armies on the other hand just got more Captains.
In the Imperial Starfleet, a Captain is generally in charge of between five and fifty thousand crew on board any given Imperial Star Destroyer. He is also in charge of his own ship, but is responsible for any and all screw ups that happen on board it. Lower ranking officers command smaller ships, but may be addressed as Captains out of respect. Captains may also command larger ships such as Executor which have higher ranked officers on board so as to free their superior from the day-to-day running of a ship.
A Captain of the Federation has similarly wide rangeing powers due to the long durations that he may spend distant from his home port. However, his ship is proportionally much smaller.