I generally know how to use a hyphen, but when should I use an en-dash (–) instead of an em-dash, or when should I use a hyphen (-) instead of an em-dash (—)?
An em-dash is typically used as a stand-in for a comma or parenthesis to separate out phrases—or even just a word—in a sentence for various reasons (e.g. a parenthetical; an ersatz-ellipsis).
School is based on the three R’s—reading, writing, and ’rithmetic.
Against all odds, Pete—the unluckiest man alive—won the lottery.
I sense something; a presence I've not felt since—
An en-dash is used to connect values in a range or that are related. A good rule is to use it when expressing a "to" relationship.
The teacher assigned pages 101–181 for tonight’s reading material.
The 2015–2016 fiscal year was the most profitable year for the new business.
New York beat Los Angeles 98–95.
A hyphen is used to join words in a compound construction, or separate syllables of a word, like during a line break, or (self-evidently) a hyphenated name.
The 40-hour workweek has become a thing of the past.
The skirt was a blue-green color.
It's pronounced hos-pi-tal-it-tee.
The minus sign is distinct from all three of the above.
4 − 2 = 2.
The figure dash (‒) is so named because it is the same width as a digit, at least in fonts with digits of equal width. This is true of most fonts, not only mono-spaced fonts.
The figure dash is used within numbers (e.g. phone number 555‒0199), especially in columns for maintaining alignment. Its meaning is the same as a hyphen, as represented by the hyphen-minus glyph; by contrast, the en dash is more appropriately used to indicate a range of values; the minus sign also has a separate glyph.
The figure dash is often unavailable; in this case, one may use a hyphen-minus instead. In Unicode, the figure dash is U+2012 (decimal 8210). HTML authors must use the numeric forms
‒ to type it unless the file is in Unicode; there is no equivalent character entity.
If you want to use the correct dash or hyphen in Stack Exchange comments, just use the appropriate HTML entity:
— for em-dash,
– for en-dash, and
− for the minus sign. The hyphen is, of course, directly on your keyboard.