This is pretty easy, but people seem to get it wrong a lot. There are at least three different symbols that are commonly referred to as a “dash.” They are the hyphen, the en dash, and the em dash. They are used differently. There are lots of resources on how to use them, but my favorite is Matthew Butterick, Typography for Lawyers, 48–49 (2010).
To summarize very quickly: hyphens are used to connect words, en dashes are used to connect either ranges of numbers or opposing pairs of words, and em dashes are a break in a sentence. As an example, Butterick’s analysis of en-dash usage on pages 48–49—which is otherwise excellent—makes one mistake. It claims that em dashes are “underused in legal writing,” when I think they are often overused. Em dashes are to lawyers what cocaine is to financiers. I’m not going to get super-judgmental about it, but people should chill with that shit. Also don’t put spaces on either side of an em dash.
Part of the problem is that outside of word-processing software, making the different symbols can be a pain. I’m sure I’ve used hyphens to connect numbers on this blog before. But in more formal writing, this is worth getting right. There are also some fussy rules on when you use hyphens, but that is another post.