An honorific is an affix, a term which precedes someone's name in conversation, which is designed to confer honor and respect on the individual in question, as well as to define him or her. Honorifics vary widely, from a simple “Mrs.” when referring to a married woman to “His Holiness” when discussing the Pope. Honorifics which relate to religious offices and royalty are sometimes known as styles of office.
The use of honorifics varies from culture to culture. As a general rule, honorifics are always used in formal situations, unless someone specifically requests that an honorific not be used. For example, someone meeting the parents of a friend would address them as Mr. and Mrs. Lastname, unless they invited that person to be less formal. People are often taught from an early age that it is better to err on the side of formality than to cause offense by being too casual.
In some cultures, the use of honorifics is more widespread, and it can get very complicated. In Japan and some other Asian cultures, for example, honorifics are used on a daily basis, and people are expected to use the right form when addressing someone. Many languages even have honorifics built into them: French speakers, for example, can choose between the formal vous and the more casual tu when saying “you.”
Some honorifics refer to a profession, as in the case of honorifics like Chef, Doctor, Professor, Coach, or Teacher. Many professions have very specific honorifics: judges, senators, priests, presidents, and dignitaries, for example, all have very specific styles of office, like “The Right Reverend” and “Your Honor” which are used in all written correspondence and in spoken conversation unless people are directed otherwise.
Honorifics are also used to describe class and social status. A Queen, for example, might be referred to as Her Imperial Highness, and various styles of office are used to describe other royalty. At times, the use of search terms can come into dispute, especially in the case of marriages between social classes. A single woman is often referred to as Ms. or Ma'am, while a man would be addressed by the honorific of Mr. or Sir.
As a general rule, it is possible to pick up the correct honorific to use for someone from conversation and the people around him or her. Since most people meet dignitaries and members of royal families under controlled circumstances, it is highly probable that they will know which honorific to use, but if in doubt, it is a good idea to ask.