Let $C_A$ be the space of all real matrices that commute with $A$. Then $C_A$ has the dimension at least $n$. Moreover, the dimension is exactly $n$ if and only if the minimal polynomial of $A$ coincides with the characteristic polynomial of $A$.
Let $J(\lambda, f)$ be the Jordan block of size $f\times f$ with $\lambda$ on the diagonal entries. Suppose that the Jordan form of $A$ is
$$
\bigoplus_{i=1}^r \oplus_{j=1}^{e_i} J(\lambda_i, f_{ij})
$$
where $\lambda_i$'s are distinct eigenvalues of $A$ and $\sum\limits_{i=1}^r\sum\limits_{j=1}^{e_i} f_{ij}=n$.
Then we are able to write down the dimension of $C_A$ in terms of $f_{ij}$:
$$
\dim C_A=\sum_{i=1}^r\sum_{j=1}^{e_i}\sum_{k=1}^{e_i} \min(f_{ij},f_{ik}).
$$
For example, if Jordan form of $A$ is $J(1,2)\oplus J(1,3)\oplus J(3,1)$, then
$$
\dim C_A = \min(2,2)+\min(2,3)+\min(3,2)+\min(3,3)+\min(1,1)=10.
$$
A computationally useful method is to use Kronecker product. The matrices in $C_A$ can be thought of the solution set of the following linear system:
$$
(I_n \otimes A - A^T \otimes I_n)\vec{x}=\vec{0}.
$$
Thus, we may use elementary row operations to make the $n^2\times n^2$ matrix $I_n \otimes A - A^T \otimes I_n$ to the reduced row echelon form, to solve the above system.