In the British Royal Navy of the 18th and 19th centuries, the term Captain had two meanings.
Post-Captain was a military rank above Commander and below flag rank (Admiral). When an officer was posted as a Captain, he was entitled to wear a Captain's epaulette on the right shoulder of his uniform, then when he attained three years in that rank was then entitled to wear the epaulette on both shoulders. (A Commander wore a single epaulette on his left shoulder.)
Once one was posted, he was added to the 'Captain's List' noting the seniority of each Captain in the service so that when more than one ship worked together, the Captain most senior was in charge. Rising to Flag ranks was usually by seniority on the Captain's List. When a Captain was promoted to Admiral, any Captains above him on the list had also to be promoted, though this often achieved by making them nominal "Yellow Admirals" ("without distinction of squadron").
Anyone commanding a naval ship was referred to as 'Captain', regardless of military rank.