This question itself is 4 words long: “how many words is this”. If you ever need to count words in a longer text, the usual method is to treat each sequence of characters separated by spaces as a word, ignoring extra spaces and line breaks. Online word counters automate this by splitting the text on whitespace and punctuation, then tallying how many resulting tokens qualify as words.