[proofplan]
We regard the homomorphism $\varphi: G \to H$ first as a function between the finite underlying sets of $G$ and $H$. If $\varphi$ is injective, its image has the same cardinality as $G$, hence the same cardinality as $H$, so the image must be all of $H$. If $\varphi$ is surjective, then a finite counting argument shows that no two elements of $G$ can have the same image. In either case $\varphi$ is bijective, and a bijective [group homomorphism](/page/Group%20Homomorphism) has a homomorphic inverse, so it is a [group isomorphism](/page/Group%20Isomorphism).
[/proofplan]
[step:Turn injectivity into surjectivity by counting the image]
Assume first that $\varphi$ is injective. Let $\varphi(G) := \{\varphi(g) : g \in G\}$ denote the image of $\varphi$ as a subset of $H$. Since $\varphi: G \to \varphi(G)$ is a bijection of sets, the finite sets $G$ and $\varphi(G)$ have the same cardinality, so $|\varphi(G)| = |G|$. Using the hypothesis $|G| = |H|$, we obtain $|\varphi(G)| = |H|$. Because $\varphi(G) \subset H$ and $H$ is finite, a subset of $H$ with cardinality $|H|$ must equal $H$. Hence $\varphi(G) = H$, so $\varphi$ is surjective. Therefore, in the injective case, $\varphi$ is bijective.
[/step]
[step:Turn surjectivity into injectivity by counting the domain]
Assume now that $\varphi$ is surjective. For each element $h \in H$, define the fibre over $h$ by $F_h := \{g \in G : \varphi(g) = h\}$.
Surjectivity says that every fibre $F_h$ is nonempty. The fibres are pairwise disjoint, and their union is $G$, because every $g \in G$ belongs to exactly the fibre $F_{\varphi(g)}$.
Since $H$ is finite, summing the cardinalities of these disjoint fibres gives $|G| = \sum_{h \in H} |F_h|$.
Each term satisfies $|F_h| \ge 1$, so $|G| \ge |H|$.
But the hypothesis gives $|G| = |H|$. Therefore every term in the sum must be exactly $1$: $|F_h| = 1$ for every $h \in H$.
Thus no two distinct elements of $G$ have the same image under $\varphi$, so $\varphi$ is injective. Therefore, in the surjective case, $\varphi$ is bijective.
[guided]
Assume that $\varphi$ is surjective. The goal is to prove injectivity, meaning that each element of $H$ has at most one preimage in $G$. Since surjectivity already gives at least one preimage, it is enough to prove that each element of $H$ has exactly one preimage.
For each $h \in H$, define the fibre over $h$ by $F_h := \{g \in G : \varphi(g) = h\}$.
This notation records all elements of $G$ that map to the same element $h$. Because $\varphi$ is surjective, every $h \in H$ has at least one preimage, so $|F_h| \ge 1$ for every $h \in H$.
The fibres are pairwise disjoint: if $g \in F_h \cap F_{h'}$, then $\varphi(g) = h$ and $\varphi(g) = h'$, hence $h = h'$. Their union is all of $G$, because every $g \in G$ lies in the fibre $F_{\varphi(g)}$. Since $G$ and $H$ are finite, we may count $G$ by adding the sizes of these disjoint fibres: $|G| = \sum_{h \in H} |F_h|$.
Each summand is at least $1$, so the right-hand side is at least the number of elements of $H$: $|G| = \sum_{h \in H} |F_h| \ge \sum_{h \in H} 1 = |H|$.
The theorem assumes $|G| = |H|$. Therefore the inequality above is actually an equality, and this can happen only if no fibre has more than one element. Since every fibre already has at least one element, we get $|F_h| = 1$ for every $h \in H$.
Now suppose $g_1, g_2 \in G$ satisfy $\varphi(g_1) = \varphi(g_2)$. Let $h := \varphi(g_1) = \varphi(g_2)$. Then both $g_1$ and $g_2$ lie in $F_h$. Since $|F_h| = 1$, we must have $g_1 = g_2$. Hence $\varphi$ is injective.
[/guided]
[/step]
[step:Conclude that a bijective homomorphism is an isomorphism]
In either case, $\varphi$ is both injective and surjective. Hence $\varphi: G \to H$ is a bijective group homomorphism.
It remains only to verify the inverse homomorphism property under the convention that an isomorphism is a homomorphism with a homomorphic inverse. Let $\psi: H \to G$ denote the inverse function of the bijection $\varphi$. Take arbitrary elements $h_1, h_2 \in H$. Define $g_1 := \psi(h_1)$ and $g_2 := \psi(h_2)$, so that $\varphi(g_1) = h_1$ and $\varphi(g_2) = h_2$. Since $\varphi$ is a group homomorphism, $\varphi(g_1 g_2) = \varphi(g_1)\varphi(g_2) = h_1 h_2$. Applying the inverse function $\psi$ to both sides gives $\psi(h_1 h_2) = g_1 g_2 = \psi(h_1)\psi(h_2)$. Thus $\psi$ is a group homomorphism. Therefore $\varphi$ is a group isomorphism.
[/step]