From Wikipedia: In the Uk and commonwealth it is proper to use the title Sir prefixed to either the given name or full name. It is never proper to use the surname alone. Thus for the individual John Doe, "Sir John Doe" or "Sir John", never "Sir Doe".
The term "Dame" in the modern usage is a woman who is knighted and follows the same rules as the male counterpart, so for Jane Doe, it is proper to call her "Dame Jane", or "Dame Jane Doe" but not "Dame Doe". Historically, Dame may be the wife of a knight and thus follows the same rules as "Lady" below.
The title of "Lady" is the modern title for a woman who is married a knighted man and it is only proper to use her surname with the title, thus, Sarah Doe, Sir John Doe's wife would be "Lady Doe" and not "Lady Sarah" or "Lady Sarah Doe". This would also hold for a knight's widow.
All of these honorifics are held true for a title of baronage with exception to a widow. A widow baronet will be given the title of Dowager followed by their titled name so Lady Doe, wife of the late Sir John Doe Baronet, would be properly addressed as Dowager Lady Doe.
Common officers in the military are refered to as just "Sir" (if and only if the officer out ranks you) or "[simple rank] [Surname]" in both the UK and US. Simple rank means that you use Lieutenant for both the army ranks of Second and First Class Lieutenant (simply Lieutenant in the British Army) and the naval ranks of Lieutenant Junior Class and Lieutenant. Commander for the naval ranks of Lieutenant Commander and Commander, Colonel for bot the army ranks of Lieutenant Colonel and Colonel. General for all US Army-style Flag Ranks, and Admiral for all US Naval-style Flag Ranks. In the UK the lowest army flag officer is calle Brigadier and the lowest naval flag officer is a Commodore. The US lowest flag rank may or may not properly be called Comodore depending on the time as it is at present no longer a rank and has a weird history. The rank proper was first abandoned in 1899, only to return as a flag rank in WWII and dropped after the war for Rear Admiral, Lower Half (a Junior Rear Admiral, Upper Half, having identical insignia). That said, it was the billet title for Senior Naval Captains, who commanded more than one ship or were the CAG of aircraft Carrier Squadron until the early 1980s when it was again adopted as the lowest flag rank, before the title was changed 6 months later to Commodore Admiral only to be replaced by Rear Admiral, Lower Half again (but this time given a one star insignia). If you're a Trekkie, this is why Captain Kirk had a superior of rank of Comodore while Picard had a superior of the rank Rear Admiral, Lower Half: The former followed 60s naval ranks while the later was following mid-80s naval ranks.
Finally, while not a hard rule, the general rule is in Naval tradition is that a ship must have exactly one "Captain" even if the senior officer on the ship is not of that rank. A Commander in charge of a Destroyer (common) may be called Captain while in that role by the crew only. A Commander in charge of a Submarine however is always a Commander (because a Submarine is a Boat, not a ship in naval traditions. Don't ask me why I don't know). Also I have heard of traditions where someone with an Army rank of Captain onboard a ship will be called Major instead of Captain for the duration of his time on the ship because he is not the Captain (of the ship) and addressing him by the next lowest rank (Lieutenant) is disrespectful as opposed to addressing him as the next highest rank (Major). Finally, it is pronounced Left-tenant in the UK and Loo-tenant in the U.S. though this is accent and not formal. Either way when written it's always spelled out as "Lieutenant" regardless of service though in fiction, the "Left-tenant" spelling may be used in dialog to establish that the character has an accent. The US pronunciation is close enough to the spelling that it's left alone unless some Brit writer wants to be cheeky and say it's the U.S. that's pronouncing it wrong.
Enlisted Personel and NCOs are always [Rank] [Surname] except in the UK where RAF Warrant officers are reffered to as "Sir" by subordinants and Mr/Ms/Mrs [surname] by superior officers. US NCOs and Enlisted called "sir" will rebuke their underling by pointing out they "work for a living".
In both military systems a female officer of superior rank will be addressed as either Ma'am or Sir though the latter is a relatively new honorific and it is customary to ask for a preference if any, though neither use will be incorrect in the context of insubordination to an officer.
Finally while foreigners may be Knighted, they may not use the Prefix "Sir" as the Knighthood is in this case Honory, but may append the letters of the particular order he was knighted in to the end of his name (these post nominal letters are simialar to academic letters familiar in the U.S. for example a Dr. John Doe maybe a MD or a PHD depending on what he received his doctoral degree in). An example of this is Mayor Rudolf "Rudy" Giuliani was given the honorary Knighthood of Knight Commander of the Most Excellent Order of the British Empire (Letters: KBE) in 2002. It is improper to refer to him as Sir Rudolf Giuliani, but it is proper to style his name as "Mayor Rudolf Giuliani, KBE" (In the U.S., political office titles are retained after you leave office and while there is no formal rule, the highest office held is preferred unless you currently hold a different office in another Branch or greater importance. A legislator who was both in he house and Senate would be Senator). You may only use "Sir" if you are a citizen of a country which recognizes the Monarch of England as the Head of State. Also, if you are a knight, while addressing your peers. Thus Sir John Doe and Dame Jane Doe would address each other as John Doe and Jane Doe. Among other Nobility, the noble title. Those with title for their heir apperent (Dukes, Earls, and Marquess) who are knighted are "Lord [given name]" as the tile of lord takes precedence though the letters of the order will be used at the end of the name, while the heir apparent of Barons and Viscounts are "The Honorable Sir [Full Name] or [Given Name]" or "The Hon. Sir..." in writing.