From linear algebra we know that given vector spaces $V$, $W$ over a field $k$ and a linear map $f\colon V\to W$ we have $$\dim V = \dim \operatorname{im} f + \dim \ker f.$$
Is this still true when we consider free $\mathbb Z$-modules (i.e. free abelian groups) instead of vector spaces? Given a homomorphism $f\colon G\to H$ between free $\mathbb Z$-modules, do we have $$\operatorname{rk}(G) = \operatorname{rk}\operatorname{im} f + \operatorname{rk}\ker f?$$
To provide some context: This question comes up when computing homology groups of free chain complexes, where we need to check if some generating set of a kernel is a basis. Using the rank nullity theorem for free $\mathbb Z$-modules is an appealing way to do this.