Possible valid and invalid codewords I have already read different things about hamming distance, hamming code, detection and correction of memory errors, but I am still not understanding many things. 

I know that the hamming distance between 2 codewords is the number of bits to be reversed to convert one codeword into the other.

I know that the hamming code is the set of all possible codewords. The codewords are composed of data bits and control bits, hence the number of bits in a codeword is n = m + r, where m is the number of data bits and r is the number of check bits. And the number of possible codewords with n bits should be $2^n$.

One thing I am not understanding is what are these valid and invalid codewords and how to 'calculate' them? Why a codeword is valid and invalid? What is the connection with the parity bits? How to find an invalid codeword?

I'm sorry if I am asking many things together, but I am really not understanding exactly the concepts I cited above.
There's no such thing as a "valid" or "invalid" codeword. If a string of bits is a codeword in a particular code such as a Hamming code, it's "valid"; if it's not a codeword, it's "invalid".