The complete specification has 17 rules about when emphasis begins and ends. To summarize, I wrote three rules for myself:
- Use either asterisks or underscores to emphasize a character next to a space, punctuation, or the beginning or end of a line. Put an emphasis mark immediately next to a character, with no space between.
Exception. Special punctuation marks override this rule, including a backslash, backtick, and square brackets which cause an asterisk or underscore to be rendered as a character and ignored as an emphasis mark.
- Use an asterisk to emphasize letters and numbers next to letters and numbers. By contrast, an underscore is not an emphasis mark between letters and numbers, as in not_italic.
- To emphasize punctuation next to letters and numbers, use HTML tags. By contrast, an asterisk and underscore cannot emphasize punctuation next to an unemphasized letter or number.
To see these rules with examples, see Emphasis in GitHub Flavored Markdown.