Madam or ma'am is a title for a woman. It is derived from the French madame, the equivalent of Mrs. or Ms., and literally signifying "my lady." The plural of madam in this sense is mesdames.
After addressing her as "Your Majesty," it is proper to address The Queen of the United Kingdom as "Ma'am" for the remainder of the conversation.
However, the title Madam Justice is used in third-person reference: Madam Justice Louise Arbour, Madam Justice Arbour.
In the United States Supreme Court, rather than adopting the title Madam Justice for female justices, the title Mr. Justice was replaced simply by Justice. Likewise, female presidents of the Republic of Ireland have preferred to be addressed simply as President in direct address, rather than Madam President. Female judges of the High Court of Justice of England and Wales are titled Mrs. Justice rather than Madam Justice, regardless of marital status. However, District Judges are referred to as either Madam or Ma'am.
In the United States Armed Forces, "ma'am" (to rhyme with "jam") is used to address a female commissioned officer. Marine recruits and Air Force trainees also address female non-commissioned officers as "ma'am."
Possibly the shortness of the word helps explain another, in a sense compensating, idiomatic but non-official practice in American English: emphatically saying Ma'am both in front and behind an obedient response in clear voice to the senior, especially during drill, e.g. 'Ma'am, yes, ma'am!'
Under the Ancien régime, Madame was the wife of Monsieur, the eldest of the King's brothers.