Rank answers one question: how many independent directions survive the map x↦Ax?
This one number decides whether Ax=b has a solution, whether the solution is unique, and how
much a matrix can be compressed. Low rank is everywhere in ML: a LoRA update BA has rank at
most r, an attention score matrix QK⊤ has rank at most the head dimension, and PCA keeps a
low-rank part of the data. In science, the four subspaces of a graph's incidence matrix describe
Kirchhoff's laws for electric circuits.
The column spaceC(A)={Ax:x∈Rn}⊆Rm is the set of all outputs.
The null spaceN(A)={x:Ax=0}⊆Rn is the set of inputs that are sent to zero.
The rankr=dimC(A) is the number of independent output directions.
Start with a square example in R3. A matrix of rank 3 turns the unit cube into a solid
box. A matrix of rank 2 flattens the cube into a parallelogram inside a plane: one input direction
is lost. A matrix of rank 1 flattens everything onto a line: two input directions are lost.
Interactive figure: loading…
Press Squash (play), or move the slider t from 0 to 1. Every point moves from x to Ax.
The aqua cube becomes a flat parallelogram in the plane C(A), and the
orange null-space line shrinks to the point 0. Read the count:
rank 2 + nullity 1 = 3. Switch to rank 1: the image is a line and a whole plane of inputs goes to 0
(1 + 2 = 3). Edit the matrix: the count always gives 3.
Rank–nullity is a counting statement about the n input dimensions. Some of them are sent to 0
(that is dimN(A)). The rest are carried one-to-one onto the output directions (that is r).
So r+dimN(A)=n: each input direction is counted exactly once.
Two more subspaces come from A⊤: the row spaceC(A⊤)⊆Rn (all
combinations of the rows of A) and the left null spaceN(A⊤)={y:A⊤y=0}⊆Rm.
Interactive figure: loading…
All four subspaces of a 2×3 matrix. On the left is the input space R3: the
row space and the null space meet at a right angle.
On the right is the output space R2: the column space and the
left null space. Move x with the sliders: it splits into
xrow+xnull, and only xrow changes Ax.
Switch to rank 1 and watch every dimension in the table move by one.
The figure is the whole lesson in one picture. A sends the row space one-to-one onto the
column space (both have dimension r), and it sends the null space to 0. The two pieces on each
side are perpendicular, and their dimensions add up to n on the input side and to m on the
output side.
Quick check
A 2×3 matrix A has rank 2. What is its null space?
Why.
The inputs live in R3(n=3), so N(A)⊆R3, and rank–nullity gives dimN(A)=3−2=1: a line. Rank 2 is the largest possible for 2 rows, but there are 3 input directions, so one of them must be lost. R2 is the home of the outputs, not of the null space.
Row 3 − row 2 gives (0,0,0,0). This is the echelon form:
U=1001103100−10.
The first nonzero entry of each nonzero row is a pivot (boxed). Each pivot sits to the right of
the pivot above it. Columns 1 and 2 contain pivots: they are the pivot columns. Columns 3 and 4
have no pivot: they are the free columns, and x3,x4 are the free variables of Bx=0.
To reach the reduced row echelon form (RREF), make every pivot 1 and clear the entries above
each pivot. Here row 1 − row 2 gives (1,0,2,1):
Elimination multiplies A on the left by an invertible matrix E (the product of the row
operations) and gives R=EA. Three facts make this useful:
The null space does not change.Ax=0⟺EAx=0, because E is invertible.
The row space does not change. Every row of R is a combination of rows of A, and
the other way round (use E−1).
The column space does change, but the dependencies between columns do not. A
combination of columns is zero in A exactly when it is zero in R (this is fact 1: the
coefficients form a null vector).
Fact 3 on the example. In R you can read the dependencies at once: column 3 of R is
(2,1,0)=2⋅(column 1)+1⋅(column 2), and column 4 is
(1,−1,0)=column 1−column 2. The same holds in B:
2121+132=374=column 3 of B,121−132=0−1−1=column 4 of B.
But the columns themselves changed: column 1 of B is (1,2,1), while column 1 of R is (1,0,0).
So the rank is the number of pivots. A basis of C(A) is given by the pivot columns of the
original A, and a basis of C(A⊤) by the nonzero rows of R.
Quick check
For B above, which vectors form a basis of the column space C(B)?
Why.
Elimination keeps the dependencies between columns but changes the columns. So the pivot positions (columns 1 and 2) come from R, and the vectors come from B. The pivot columns of R span the plane x3=0, which is not C(B): for example, (1,2,1)∈C(B) has x3=0. The nonzero rows of R live in R4; they are a basis of the row space. The free columns (3,7,4) and (0,−1,−1) do lie in C(B), but they are combinations of the pivot columns, and the pivot columns are the standard choice that elimination gives you.
The pivot columns of A and the nonzero rows of R give a factorization. Let C be the
m×r matrix of pivot columns of A, and let Rr be the r×n matrix of nonzero rows
of rref(A). Then
A=CRr.
Why. Column j of Rr lists how column j of rref(A) is built from its pivot
columns, which are e1,…,er. By fact 3, column j of A is built from the pivot
columns of A with the same coefficients: column j of A=C⋅(column j of Rr).
This is the column view of the product (lesson 01).
For the example, C holds columns 1 and 2 of B:
B=121132(1001211−1).
Check column 4: 1⋅(1,2,1)−1⋅(1,3,2)=(0,−1,−1) ✓.
Theorem (row rank = column rank). For every matrix, dimC(A⊤)=dimC(A).
Proof.
Let r=dimC(A) (the column rank). Write A=CRr with Rr of size r×n.
By the row view of the product, every row of A is a combination of the r rows of Rr. So
the row space of A is spanned by r vectors: dimC(A⊤)≤dimC(A).
Apply step 2 to A⊤, whose rows are the columns of A:dimC(A)≤dimC(A⊤).
The two inequalities give equality. ■
The factorization also shows the rank in the outer-product view: A=CRr is a sum of r rank-1
matrices (column k of C times row k of Rr). LoRA, low-rank attention and the truncated SVD
(lesson 08) all use this form.
Quick check
u,v,w,z are nonzero vectors in R5. What can you say about rank(uv⊤+wz⊤)?
Why.
uv⊤+wz⊤=[uw](v⊤z⊤), so every column is a combination of u and w: the rank is at most 2. It can be smaller: if u and w are parallel the rank is at most 1, and with w=u,z=−v the sum is the zero matrix (rank 0).
Theorem (rank–nullity). For A∈Rm×n:rank(A)+dimN(A)=n.
Proof.
Reduce A to echelon form R. By fact 1, N(R)=N(A).
R has r pivot columns and n−r free columns.
For each free variable j: set xj=1, set the other free variables to 0, and solve
for the pivot variables by back substitution. Call the result sj (a special solution).
The sj are independent: sj has a 1 in position j, where every other special
solution has a 0.
The sj span N(A): for any x∈N(A), the vector x−∑jxjsj is in N(A)
and has all free variables equal to 0; back substitution then forces its pivot
variables to 0 too, so it is the zero vector.
Hence dimN(A)=n−r.■
For B: the free variables are x3 and x4. With x3=1,x4=0 the rows of R give
x1=−2,x2=−1, so s3=(−2,−1,1,0). With x3=0,x4=1:x1=−1,x2=1, so
s4=(−1,1,0,1). Two special solutions, and 4−2=2 ✓.
The last two rows use rank–nullity for A; the first two use it for A⊤ (which has m
columns and the same rank r).
N(A)⊥C(A⊤). If Ax=0, then every row ai⊤ of A satisfies ai⊤x=0:x is orthogonal to every row, so also to every combination of rows. The same argument for
A⊤ gives C(A)⊥N(A⊤). More is true: the two pieces fill their space.
Theorem (orthogonal complements).N(A) and C(A⊤) are orthogonal complements in
Rn: every x∈Rn splits in exactly one way as x=xrow+xnull
with xrow∈C(A⊤) and xnull∈N(A). The same holds for C(A) and N(A⊤) in Rm.
Proof: the two pieces fill Rn
They share only 0. If x is in both, then x⊥x, so ∥x∥2=x⊤x=0 and x=0.
Their bases together are independent. Take a basis r1,…,rr of C(A⊤) and a basis
s1,…,sn−r of N(A). Suppose ∑iairi+∑jbjsj=0. Then
u=∑iairi=−∑jbjsj lies in both subspaces, so u=0 by step 1. Each basis is
independent, so all ai=0 and all bj=0.
They span Rn. Step 2 gives r+(n−r)=n independent vectors in Rn, so
they form a basis of Rn (lesson 01). Every x is a combination of them: the part with the
ri is xrow, the part with the sj is xnull.
The split is unique. If x=p+q=p′+q′ with p,p′ in the row space and q,q′ in the
null space, then p−p′=q′−q lies in both subspaces, so it is 0 by step 1.
For C(A) and N(A⊤), apply steps 1–4 to A⊤.■
Two consequences you will use again and again:
Solvability:Ax=b has a solution exactly when b∈C(A), that is, when
y⊤b=0 for every y∈N(A⊤). (By the theorem, b∈C(A) exactly when b has no
part in N(A⊤).)
Splitting: every x splits as x=xrow+xnull.A ignores
xnull and maps the row space one-to-one onto the column space.
Pivots in columns 1 and 3, so r=2. Free variables: x2,x4.(R is already reduced: the
pivots are 1 and the entries above them are 0.)
Interactive figure: loading…
Step through the elimination. Press Next step to apply one row operation at a time. Each
operation acts on A and on I together, so the right block becomes the matrix E with EA=R.Pivot columns and free columns are marked as soon as
elimination decides them. At the end the widget reads off bases of all four subspaces, in the colours
of the figures above; the last row of E is the left null vector (−1,−1,1). Try needs a row swap,
or type your own matrix.
A=CR. The pivot columns (1,2,3) and (0,1,1) times the two nonzero rows of R:
column 4 of A is 1⋅(1,2,3)+2⋅(0,1,1)=(1,4,5) ✓, and column 2 is 2⋅(1,2,3) ✓.
Checks.s1⋅(1,2,0,1)=−2+2=0 and s2⋅(0,0,1,2)=−2+2=0: null space ⟂ row space.
Ax=b is solvable exactly when y⊤b=−b1−b2+b3=0, that is, b3=b1+b2.
Quick check
For this A, which right-hand side b gives a solvable system Ax=b?
Why.
The test is y⊤b=0 for y=(−1,−1,1), that is, b3=b1+b2. Only (1,1,2) passes: −1−1+2=0. A wide matrix does not reach every b unless its rank equals the number of rows; here r=2<3, so C(A) is a plane in R3.
The library computes all four subspaces, so you can check the hand computation. The notebook for
this lesson has these cells and the exercises.
importnumpyasnpfromscipy.linalgimportnull_space,orthA=np.array([[1,2,0,1],[2,4,1,4],[3,6,1,5]],dtype=float)r=np.linalg.matrix_rank(A)# counts singular values above a toleranceN=null_space(A)# orthonormal basis of N(A), shape (4, 2)LN=null_space(A.T)# orthonormal basis of N(Aᵀ), shape (3, 1)Rb=orth(A.T)# orthonormal basis of C(Aᵀ), shape (4, 2)print(r,N.shape[1],LN.shape[1])# 2 2 1print(np.abs(Rb.T@N).max())# ~6e-16: row space ⟂ null spaceprint(np.linalg.matrix_rank(A.T@A))# 2: rank(AᵀA) = rank(A)
In floating point, rank is a numerical idea: matrix_rank counts singular values above
σmax⋅max(m,n)⋅ε. A tiny perturbation makes almost every
matrix full rank, so in practice you look at the singular values (lessons 08 and 13).
Least squares and identifiability. If two features are collinear, N(X)={0} and
infinitely many weight vectors fit equally well. Ridge regression picks one.
Low rank in ML. LoRA: rank(BA)≤r. Attention: rank(QK⊤)≤dk.
Outer product: rank(uv⊤)=1. In general rank(AB)≤min(rankA,rankB).
Graphs and conservation laws. The incidence matrix A of a directed graph has one row per
edge and one column per node, with +1 at the start node and −1 at the end node of each edge
(the convention of the notebook). Then:
Av gives the potential differences along the edges;
for a connected graph, N(A) is the constant potentials (dimension 1);
A⊤y=0 means flows that are conserved at every node (Kirchhoff's current law);
dimN(A⊤)=E−N+1, the number of independent loops;
A⊤A is the graph Laplacian, the basis of spectral graph methods and GNNs.
A is 5×3 with rank 3. Give the dimensions of the four subspaces.AnswerC(A): 3 (in R5);N(A⊤): 2; C(A⊤): 3, so all of R3;N(A): 0.
Why do row operations not change the null space?AnswerThey multiply by an invertible E, and EAx=0⟺Ax=0.
What is rank(AA⊤)?Answerrank(A). Apply the theorem rank(M⊤M)=rank(M) to M=A⊤:rank(AA⊤)=rank(A⊤)=rank(A) (row rank = column rank).
In the worked example, what happens for b=(1,1,0)?Answerb3=b1+b2, so y⊤b=−2=0: no solution. Only a least-squares solution exists.
Can a 4×4 matrix have C(A)=N(A)?AnswerYes, with r=2 (needs r=4−r) and A2=0. Example: ones at positions (1,3) and (2,4), zeros elsewhere; then C(A)=N(A)=span(e1,e2).
Write (122436) as CR.AnswerRank 1: row 2 = 2·row 1, and the only pivot column is column 1. C=(12),R=(123), so the matrix is the outer product (12)(123).
Recall cardsAnswer in your head first, then reveal. Add the cards to your review deck to see them again just before you would forget.
Define the rank of a matrix A.
dimC(A): the number of independent columns. After elimination it is the number of pivots.
State rank–nullity for A∈Rm×n.
rank(A)+dimN(A)=n, the number of columns.
An m×n matrix has rank r. Give the dimensions of C(A),N(A⊤),C(A⊤) and N(A).
r and m−r (in Rm);r and n−r (in Rn).
Why is N(A) orthogonal to the row space C(A⊤)?
Ax=0 says that x has dot product 0 with every row of A, so also with every combination of rows.
After elimination A→R, where do you take a basis of C(A) from?
The pivot columns of the original A. Elimination changes the columns but keeps the dependencies between them.
How do you test with the left null space whether Ax=b has a solution?
It has one exactly when y⊤b=0 for every y∈N(A⊤), that is, when b∈C(A).
What are C and R in the factorization A=CR?
C = the r pivot columns of A(m×r);R = the r nonzero rows of rref(A)(r×n).
Why does row rank equal column rank?
A=CR with r = column rank, so every row of A is a combination of the r rows of R: row rank ≤ column rank. The same for A⊤ gives the other inequality.
Why is rank(A⊤A)=rank(A)?
N(A⊤A)=N(A): if A⊤Ax=0 then ∥Ax∥2=x⊤A⊤Ax=0. Both have n columns, so rank–nullity gives equal ranks.
A 3×5 matrix has rank 3. What is dimN(A)?
5−3=2. A wide matrix always has a nonzero null space.
The notebook for this lesson runs in Colab. It has four exercises, each with a check cell
and a folded solution:
Write rref: Gauss–Jordan elimination with a tolerance, returning R and the pivot columns.
Build a basis of N(A) from the special solutions, and check rank–nullity on random low-rank
matrices.
Decide whether Ax=b is solvable with the left null space: y⊤b=0 for every
y∈N(A⊤).
Build the incidence matrix of a small circuit graph and read Kirchhoff's laws from its four
subspaces: one constant potential, E−N+1 loops, and A⊤A = the graph Laplacian.
Open on YouTube · the player loads from youtube-nocookie.com when you press playOpen on YouTube · the player loads from youtube-nocookie.com when you press playOpen on YouTube · the player loads from youtube-nocookie.com when you press play
Sheldon Axler, Linear Algebra Done Right, 4th edition, free PDF:
§3B (null spaces and ranges; 3.21, the fundamental theorem of linear maps, is rank–nullity) and
§3C (3.57: column rank equals row rank).
Code along in Colab
Runs in your browser with nothing to install. The notebook repeats the key demos and has exercises with checks; solutions are inside, folded.