Rank of the $n \times n$ matrix with ones on the main diagonal and $a$ off the main diagonal I want to find the rank of this $n\times n$ matrix
\begin{pmatrix}
1 & a & a & \cdots & \cdots & a \\
a & 1 & a & \cdots & \cdots & a \\
a & a & 1 & a & \cdots & a \\
\vdots & \vdots & a& \ddots & & \vdots\\
\vdots & \vdots & \vdots & & \ddots & \vdots \\
a & a & a & \cdots  &\cdots & 1
\end{pmatrix}
that is, the matrix whose diagonals are $1's$ and $a$ otherwise, where $a$ is any real number.
My first observation is when $a=0$ the rank is $n$ and when $a=1$ the rank is $1.$ Then I can assume $a\neq 0, 1$ and proceed row reduction to find its pivot rows. I obtain
\begin{pmatrix}
1 & a & a & \cdots  & a \\
0 & 1+a & a & \cdots & a \\
0 & a & 1+a & \cdots & a \\
\vdots & \vdots & \vdots & \ddots & \vdots \\
0 & a & a & \cdots  & 1+a
\end{pmatrix}
by subtracting the first row multiplied $a$ for each row below the first, and then divides the factor $(1-a)$, 
and stuck there. Any hints/helps?
 A: Let
$$\mathrm M_n (a) := \begin{bmatrix} 1 & a & a & \dots & a & a\\ a & 1 & a & \dots & a & a\\ a & a & 1 & \dots & a & a\\ \vdots & \vdots & \vdots & \ddots & \vdots & \vdots\\ a & a & a & \dots & 1 & a\\ a & a & a & \dots & a & 1\end{bmatrix} = (1-a) \mathrm I_n + a 1_n 1_n^{\top}$$
The eigenvalues of rank-$1$ matrix $a 1_n 1_n^{\top}$ are 


*

*$\color{blue}{0}$ with multiplicity $n-1$.

*$\color{blue}{n a}$ with multiplicity $1$. 


Thus, the eigenvalues of $\mathrm M_n (a) = (1-a) \mathrm I_n + a 1_n 1_n^{\top}$ are 


*

*$\color{blue}{1-a}$ with multiplicity $n-1$.

*$(1-a) + na = \color{blue}{(n-1) \, a + 1}$ with multiplicity $1$. 


We could also have arrived at this conclusion computing the characteristic polynomial of $\mathrm M_n (a)$
$$\begin{array}{rl} \det ( s \mathrm I_n - \mathrm M_n (a) ) &= \det \left( (s-(1-a)) \mathrm I_n - a 1_n 1_n^{\top} \right)\\ &= \det \left( (s-(1-a)) \left( \mathrm I_n - \frac{a}{s-(1-a)} 1_n 1_n^{\top} \right) \right)\\ &= (s-(1-a))^n \cdot \det \left( \mathrm I_n - \frac{a}{s-(1-a)} 1_n 1_n^{\top} \right)\\ &= (s-(1-a))^n \cdot \left(1 - \frac{n a}{s-(1-a)}\right)\\ &= (s-(1-a))^{n-1} \cdot \left(s-(1-a) - n a\right)\\ &= (s-(1-a))^{n-1} \cdot \left( s - ((n-1) \, a + 1) \right)\end{array}$$
where the matrix determinant lemma was used. If
$$a \in \left\{ -\frac{1}{n-1}, 1 \right\}$$ 
then $\mathrm M_n (a)$ is singular. Thus, using the rank-nullity theorem, we conclude that
$$\boxed{\mbox{rank} (\mathrm M_n (a)) = \begin{cases} 1 & \text{if } a = 1\\ n-1 & \text{if } a = -\frac{1}{n-1}\\ n & \text{otherwise}\end{cases}}$$
A: If you haven't figured it out yet here's the solution: if $a=1$ $\mathrm{Rank}(A)=1$ otherwise $\mathrm{Rank}(A)=n$ where 
$$A:= \begin{pmatrix}
1&a&a&\cdots&a\\
a&1&a&\cdots&a\\
a&a&1&\cdots&a\\
\vdots&\vdots&\vdots&\ddots&\vdots\\
a&a&1&\cdots&1
\end{pmatrix}$$
You've already shown that you know if $a\in\{0,1\}$. So as for the rest, your close to a solution. The next set of Row equations are as follows $R_i-R_1 \to R_i$ such that $1<i\leq n$. This gives the matrix,
$$A_2= \begin{pmatrix}
1&a&a&\cdots&a\\
-1&1&0&\cdots&0\\
-1&0&1&\cdots&0\\
\vdots&\vdots&\vdots&\ddots&\vdots\\
-1&0&0&\cdots&1
\end{pmatrix}$$
The next Row equation is $\frac{R_1-\sum_{i=2}^n aR_i}{1+a(n-1)}\to R_1$. This gives the matrix
$$A_3= \begin{pmatrix}
1&0&0&\cdots&0\\
-1&1&0&\cdots&0\\
-1&0&1&\cdots&0\\
\vdots&\vdots&\vdots&\ddots&\vdots\\
-1&0&0&\cdots&1
\end{pmatrix}$$
The next Row equations are $R_i+R_1\to R_i$ where $1<i\leq n$. This gives
$$A_4= \begin{pmatrix}
1&0&0&\cdots&0\\
0&1&0&\cdots&0\\
0&0&1&\cdots&0\\
\vdots&\vdots&\vdots&\ddots&\vdots\\
0&0&0&\cdots&1
\end{pmatrix}=I$$
Note that $\mathrm{Rank}(A)=\mathrm{Rank}(I)=n$ as desired. 
Karma made note that if $a=\frac{1}{1-n}$ then 
$$A_3= \begin{pmatrix}
0&0&0&\cdots&0\\
-1&1&0&\cdots&0\\
-1&0&1&\cdots&0\\
\vdots&\vdots&\vdots&\ddots&\vdots\\
-1&0&0&\cdots&1
\end{pmatrix}$$
This implies that for $a=\frac{1}{1-n}$ the $\mathrm{Rank}(A)=n-1$.
