It's a style matter.
This can make it a style-guide matter. Some style-guides insist on no space, some on a space.
Those that insist on a space generally don't have a space before the degree symbol for degrees of arc, or the prime and double prime when used for minutes, seconds, inches or feet, but do before the degree symbol when used for degrees of a scale (most often with temperature, e.g. 9 °C but 9° angle).
The space should be a non-breaking space so as to keep the unit on the same line as the number.
Some technical guides as well as writing guides have rules on the matter, so for example if you were writing to a guide that wanted no spaces, but also to a technical standard such as SI or NIST which insists on spaces, you would hence probably favour the space on the basis that if you are concerned with such a technical standard, then it—being more directly relate to the technical matters—would be of more importance to you.
Guides also differ on whether you would space, hyphenate, or close in the case of an adjectival use such as "10-m pole/10m pole/10 m pole". IIRC the SI standard both says you should use a space in such cases, and then actually hyphenates itself at another point!