Let $K$ be a field, $A\in M_n(K)$ and $C(A)$ be the commutant of $A$. Clearly, if $A,B$ are similar, then $\dim(C(A))=\dim(C(B))$.
Definition. $U\in M_n(K)$ is said to be cyclic if there is $u\in K^n$ s.t. $\{u,Uu,\cdots,U^{n-1}u\}$ is a basis of $K^n$. Remark that, when $U$ is cyclic, the matrices $I,U,\cdots,U^{n-1}$ are linearly independent and, therefore, $\dim(C(U))\geq n$.
The key is the following proposition
Proposition. If $A\in M_n(K)$ is not cyclic, then there are two complementary proper subspaces of $K^n$ that are $A$-invariant.
Proof. Let $m_A=p_1^{u_1}\cdots p_k^{u_k}$ be the decomposition of the minimal polynomial of $A$ in irreducibles. If $k>1$, then, according to the kernels theorem, $K^n=\oplus_i \ker(p_i^{u_i})$ and we are done. Then we may assume that $m_A=p^u$ where $p$ is irreducible of degree $d$. If $\mathcal{B}$ is a basis of $K^n$, then there is $e\in\mathcal{B}$ s.t. $m_A$ is its minimal polynomial; thus $\{e,Ae,\cdots,A^{ud-1}e\}$ is a free system and spans $E_1$, the first $A$-invariant subspace. Note that, if $A$ is not cyclic, then $ud<n$.
EDIT. Now $A$ induces an endomorphism of $K^n/E_1$ which can be represented (as a first step) by $\pi\circ A_{|U}$ where $K^n=E_1\oplus U$ and $\pi$ is the associated projection onto $U$; let $m_1=p^v,v\leq u$ be its minimal polynomial; we consider a basis $\mathcal{B}_1$ of $\ker(m_1(A))$; by construction, there is $e_1\in \mathcal{B}_1$ s.t. $m_1$ is its minimal polynomial and s.t. $\{e_1,Ae_1,\cdots,A^{vd-1}e_1\}$ spans $E_2$, a second $A$-invariant subspace which is a direct sum with $E_1$; and so on...
Corollary. $\dim(C(A))\geq n$.
Proof. We proceed by recurrence over $n$. If $A$ is cyclic, then, according to the above remark, we are done. Otherwise, according to Proposition, there is $p\in \left\{1,\cdots,n-1\right\}$ s.t. $A$ is similar to a matrix in the form $B=\operatorname{diag}(U,V)$ where $U\in M_p(K),V\in M_{n-p}(K)$. Note that $C_1=\{\operatorname{diag}(X,Y)|X\in M_p(K),Y\in M_{n-p}(K),UX=XU,YV=VY \}$ is a subspace of $C(B)$. By the hypothesis of recurrence, $\dim(C_1)\geq p+n-p=n$ and we are done.