Madam is generally pronounced Mad'uhm (/'mædəm/ ), with the stress on the first syllable. The same pronunciation is used for (1) the polite form of address for an adult female, (2) a precocious young girl (as in '[s]he's a right little madam'), or (3) the female owner or operator of a brothel.
Ma'am (usually pronounced 'Mam' /mɑːm/ although sometimes the middle vowel is lengthened /mæm/) in the UK and most Commonwealth countries is mostly reserved for:
1/ Addressing female members of the Royal Family.
2/ In the armed forces and police force, used when addressing a female officer who has a higher rank than your own.
3/ Some schools, especially public schools, expect students to use this form of address when speaking to female teachers. NOTE: Public schools in the UK are schools that are not run by the government and which charge fees for attendance. They are usually called private schools elsewhere.
4/ Some shop assistants will use this form of address when speaking to female customers. However, this usage is becoming archaic.
In some parts of the US, particularly the South, Ma'am may be used as a polite form of address to any woman.