In this case the rank is well defined. If M has rank 3, we cannot find some other basis with 2 elements, or 4. We will show that the same holds for free modules over a commutative ring.
Let R be a commutative ring, though not necessarily a field. Now there are plenty of modules that aren't free. Consider ZM as a Z module. This is not a direct sum of copies of Z, and is not free. But, when M is free it has a basis, and the cardinality of this basis gives the rank of M. We will show that rank is well defined. A free module cannot have two different ranks.
If R is Z, the integers, then M is a free abelian group, i.e. a direct sum of independent copies of Z. If G is Z3, it is not Z4 or Z2. It can only be Z3.
Let M be a free R module with two different ranks j and k. Let H be a maximal ideal in R, and let F be the field R/H. (We need R to be commutative to make R/H a field.)
Since M has two different representations, there is an implicit module isomorphism between Rj and Rk. (If j and k are infinite, we're talking about direct sums, not direct products.) Let k be larger than j, and let e be the isomorphism from Rj onto Rk. (For our purposes, e need only be an epimorphism.) Naturally, e is defined by its action on the basis, and the image of each of the j basis elements is a linear combination of the k basis elements. For instance, e(x1) might be 3y1 + 15y7 - 83y22.
Apply an R homomorphism to Rj, that carries each component ring onto its quotient field F. In other words, each coordinate now determines a coset of H in R, which is an element of F. Call this quotient module S.
Apply a similar homomorphism to Rk, producing the module T. Thus S is the direct sum of j copies of F, and T is the direct sum of k copies of F. In other words, S and T are F vector spaces of dimensions j and k respectively.
Let e induce a map from S onto T. For starters, e maps Rj onto Rk, and a subsequen homomorphism carries Rk onto T, hence e maps Rj onto T.
Let c be an element of H, and consider e(cx1). Of course e is really two homomorphisms rolled into one, and the second homomorphism, from Rk onto T, carries c to 0. Thus e(cx1) = 0. This holds for any c in H and any of the j basis elements.
Let two linear combinations of basis elements represent the same element of S. They differ by a linear combination of basis elements with coefficients drawn from H. When e is applied to this difference, the result is 0. Thus e maps the two linear combinations to the same thing in T. In other words, e is a well defined R homomorphism from S onto T.
Again, e carries H times anything to 0 in T, so the action of H is 0. We know that e is an R module homomorphism, but it is also an F module homomorphism.
An F vector space of dimension j maps onto an F vector space of dimension k, where k is larger than j. This is impossible. Therefore j = k. The rank of a free module over a commutative ring is well defined.