An em-dash is typically used to act as a comma or parenthesis to separately out phrases—or even just a word—in a sentence for various reasons (i.e. an appositive).
An en-dash is use to connect values in a range or that are related. Saying "in years 1939–1945" or "New York beat Los Angeles 98–95" are both examples where an en-dash should be used (as I did explicitly in the examples). A good rule of from here is when you're expressing a "to" relationship.
A hyphen is used to join words in a compound construction, like "em-dash," or separate syllables of a word, like during a line break.
Finally, a minus sign is distinct from all three of the above. 4 − 2 = 2.
If you want to use the correct dash or hyphen in StackExchange comments, just use the appropriate HTML entity: —
for em-dash, –
for en-dash, and −
for the minus sign. The hyphen is, of course, on your keyboard directly.