Prove that $Z(G)$ which is the center of $G$ is a subgroup of $G$ 
Question: Let $G$ be a group. Prove that $Z(G)$ is a subgroup of $G$.

If I want to show that $Z(G)$ is a subgroup of $G$ that means I have to show that it is closed under group operation?
Here is my attempt. 
Let $a,b$ be elements in $Z(G)$ and $x$ be an element in $G$. Then $ax=xa$ which is under group multiplication commutative and under inverse $(a^{-1}) x=x(a^{-1})$. And hence $(a^{-1})bx= (a^{-1})xb=x (a^{-1})b$ which is under group operation so $(a^{-1}),b$ are elements in $Z(G)$ thus a subgroup of $G$.
Really appreciate if anyone can help me by directing me if my attempt is not good.
Thanks in advance.
 A: You need to show that $Z(G)\leq G$.

*

*First of all clearly $1\in Z(G)$ since $1x=x1$ for all $x\in G$.


*Let $a,b\in Z(G)$ then $ax=xa$ and $bx=xb$ for all $x\in G$. Then $(ab)x=a(bx)=a(xb)=x(ab)$ so $ab\in Z(G)$.


*If $a\in Z(G)$ consider its inverse $a^{-1}$ in $G$. Since $ax=xa$ for all $x\in G$ we have that $a^{-1}(ax)a^{-1}=a^{-1}(xa)a^{-1}$ so $xa^{-1}=a^{-1}x$ for all $x\in G$ namely $a^{-1}\in Z(G)$.
A: While you can do this easily by checking the conditions for a subgroup, there is a somewhat easier approach using some general facts. The set of permutations of$~G$ (that is bijections $G\to G$) is a group under function composition (this is true for any set), call it $P(G)$. Define a map $\def\ad{\operatorname{ad}}\ad:G\to P(G)$ by $\ad(g)=(h\in G\mapsto ghg^{-1})$. To see that actually $\ad(g)\in P(G)$ for all$~g\in G$, that is that $\ad(g)$ is always bijective, it suffice to check that $\ad(g^{-1})$ is the inverse map of $\ad(g)$ by a computation similar to what follows. Now show that $\ad$ is a morphism of groups, that is $\ad(g_1g_2)=\ad(g_1)\circ\ad(g_2)$ for all $g_1g_2$. One has  $\ad(g_1g_2)=(h\in G\mapsto g_1g_2h(g_1g_2)^{-1})$, whose final expression can be written as $g_1g_2hg_2^{-1}g_1^{-1}$, which is easily checked to be equal to $\ad(g_1)(\ad(g_2)(h))$, as required.
Now to conclude, check that $\def\id{\operatorname{id}}\ker\ad=\{\, g\in G\mid \ad(g)=\id\,\}=\{\, g\in G\mid \forall h\in G:\ad(g)(h)=h\,\}$  is equal to $\{\, g\in G\mid \forall h\in G:ghg^{-1}=h\,\}=Z(G)$. But then $Z(G)$ like any kernel, is a subgroup, even better a normal subgroup. (It is actually even better, namely a characteristic subgroup, but that does not follow as easily from the argument given.)
