TITLE: Principal ideal and free module
QUESTION [20 upvotes]: Let $R$ be a commutative ring and $I$ be an ideal of $R$.
Is it true that $I$ is a principal ideal if and only if $I$ is a free $R$-module?

REPLY [37 votes]: It is true that, if $R$ is a commutative ring and $I$ is an ideal of $R$, then $I$ is free iff $I$ is principal and generated by a non-zerodivisor.
Proof: Say $I$ is free.  By way of contradiction, suppose $I$ has an $R$-basis containing more than one element.  Let $e_1$ and $e_2$ be distinct elements of this basis.  Then we have $e_2e_1-e_1e_2=0$, which is impossible, since the $e_i$ are linearly independent (this is where we use commutativity).  Thus, $I$ has finite rank, and its rank is $1$.  Say $I$ is generated over $R$ by $e \in R$; notice that $e$ must be a non-zerodivisor, or else $\{e\}$ would not be linearly independent.
Conversely, suppose $I$ is a principal ideal generated by a non-zerodivisor $e$.  Then the map $R \to I$ given by $r \mapsto re$ is an isomorphism of $R$-modules.