TRIM removes all spaces before the first character, all spaces after the last character, and all duplicate spaces between characters, leaving only single spaces between words.
Example
=TRIM(" spaces spaces spaces ") returns "spaces spaces spaces" (the leading and trailing space were removed).