Let $G$ be a group containing a normal subgroup $H$ isomorphic to $D_8$. Prove that $G$ must have a nontrivial center.
I proved that the $|Z(H)|=2$. I tried to solve further by class equation but not able to reach any conclusion.
Is there any relation between $|Z(G)|$ and $|Z(H)|$?
As you noted, $D_8$ has nontrivial center, with order two.
By normality, conjugation by any element of $G$ defines an automorphism of $H$. Now, the center is always a characteristic subgroup.
Thus if we let $h\ne e\in Z(H)$, then for any $g\in G$, $ghg^{-1}=h$. Thus $h\in Z(G)$. Thus $Z(H)\le Z(G)$.