The dimension of $\mathfrak u(n)$ the Lie Algebra of the unitary group is $n^2$, since you can choose $n^2$ parameters for a skew-hermitian matrix: $n$ imaginary on the diagonal, $\frac {n()n-1)}{2}$ real and $\frac {n(n-1)}{2}$ imaginary for the upper triangle: $n+2\times\frac {n(n-1)}{2} = n+ n^2-n=n^2$
For $h\in \mathfrak {su} (n)$ you have to have a $\rm{trace}(h)=0$, so you give on parameter, resulting in a dimension of $n^2-1$.
For $\mathfrak{so}(n)$ you diagonal is empty and you are left with $\frac {n(n-1)}{2}$ imaginary entries for the upper triangle.
$$
\Omega A + A^T \Omega = 0
$$
where $A^T$ is the transpose of $A$ and $Ω$ is the skew-symmetric matrix
$$
\Omega = \begin{pmatrix} 0 & I_n \\ -I_n & 0 \\ \end{pmatrix}.
$$
The dimension of $\mathfrak u(n)$ the Lie Algebra of the unitary group is $n^2$, since you can choose $n^2$ parameters for a skew-hermitian matrix: $n$ imaginary on the diagonal, $\frac {n()n-1)}{2}$ real and $\frac {n(n-1)}{2}$ imaginary for the upper triangle: $n+2\times\frac {n(n-1)}{2} = n+ n^2-n=n^2$
For $h\in \mathfrak {su} (n)$ you have to have a $\rm{trace}(h)=0$, so you give on parameter, resulting in a dimension of $n^2-1$.
For $\mathfrak{so}(n)$ you diagonal is empty and you are left with $\frac {n(n-1)}{2}$ imaginary entries for the upper triangle.
For $\mathfrak{sp}(n)$ there is an additional symmetry involved:
which results in a dimension $n(2n+1)$...