The Royal Navy assigned Commanders and at times Lieutenants to command smaller ships. For example, when William Bligh was the Captain of the HMS Bounty (also known as HM Armed Vessel Bounty), he held the rank of Lieutenant. Those with the rank of Commander and charged with a ship were referred to as "Master and Commander" for the one officer would serve as the both the captain & sailing master. In the film a Sailing Master works among the crew and Russell Crowe's character wore two epaulettes.
It should be noted that this film was based on two of Patrick O'Brien's Aubrey / Maturin novels: Master and Commander, and Far Side of the world. At no point in the film is Aubrey referred to as "master and commander". However, in the former novel - the first in the series - Aubrey is made captain of the Sophie, which has the two masts of a brig, yet is classified as a sloop, which traditionally has one mast and which would be commanded by a lieutenant. This being the case, Aubrey referred to himself as a Captain but self-depreciatingly referring to himself as being "master and commander", which is appropriate for the man in charge of a sloop.
While the first of the Hornblower novels was published in 1937, the first Aubrey / Maturin novel was published in 1969. A major difference between the two series is that Aubrey author Patrick O'Brien did extensive research on the actual ships and engagements; incorporating them (with occasional time adjustments) into the novels. In addition, O'Brien conducted extensive research on every component of a sailing ship and he provided a great deal of this technical information in his books, including the name, purpose and rigging of every sail.
In addition to providing some degree of inspiration for the Aubrey / Maturin series, the Hornblower series was the inspiration for the original Star Trek series.
Marketing text about the author stated that he gained his experience in sailing in his youth. A minor scandal arose when it was discovered that this experience was limited to only a few months and without ever actually handling a ship. In addition, it later came out that O'Brien was an absolutely terrible sailor. Being a guest one day on a sailing ship owned by a friend and admirer, his actions revealed that he had no practical understanding of how a sailing ship functioned in real life, no feel for the wind, and absolutely no awareness of how to handle a ship. He was so inept as to be dangerous. Once during that brief excursion he came about in such a way that the boom came swinging across, nearly knocking his host overboard and coming within inches of causing him serious injury.