AI Knowledge Tree

Rank, nullity, and the four fundamental subspaces

Prove the rank–nullity theorem and use the four fundamental subspaces to decide when Ax=b is solvable and how many solutions there are.

⏱ 34 minPrerequisites:Linear maps and matrices

The matrix AA of a linear map T:Rn→RmT: \mathbb{R}^n \to \mathbb{R}^m carves out four subspaces: two inside the domain, two inside the codomain. Their dimensions are linked by a single equation, and that equation tells you everything about the solvability of Ax=bAx = b.

The four fundamental subspaces

For an m×nm \times n matrix AA:

SubspaceSpaceDefinition
Column space col⁡(A)\operatorname{col}(A)Rm\mathbb{R}^m{Ax:x∈Rn}\{Ax : x \in \mathbb{R}^n\}
Null space null⁡(A)\operatorname{null}(A)Rn\mathbb{R}^n{x:Ax=0}\{x : Ax = 0\}
Row space row⁡(A)\operatorname{row}(A)Rn\mathbb{R}^ncol⁡(A⊤)\operatorname{col}(A^\top)
Left null spaceRm\mathbb{R}^m{y:A⊤y=0}\{y : A^\top y = 0\}

The column space is where AxAx can land; the null space is what AA collapses to zero. The rank is r=dim⁡col⁡(A)r = \dim\operatorname{col}(A), the number of linearly independent columns (equivalently, independent rows: row rank equals column rank, a nontrivial fact[1]). The nullity is dim⁡null⁡(A)\dim\operatorname{null}(A).

Rank–nullity theorem

Theorem. For any A∈Rm×nA \in \mathbb{R}^{m \times n}[2],

rank⁡(A)+nullity⁡(A)=n.\operatorname{rank}(A) + \operatorname{nullity}(A) = n.

Proof. Let r=rank⁡(A)r = \operatorname{rank}(A) and k=nullity⁡(A)k = \operatorname{nullity}(A); pick a basis {z1,…,zk}\{z_1, \dots, z_k\} for null⁡(A)\operatorname{null}(A). Extend it to a basis of Rn\mathbb{R}^n by adding {w1,…,wr}\{w_1, \dots, w_r\}.

Step 1: {Aw1,…,Awr}\{Aw_1, \dots, Aw_r\} spans col⁡(A)\operatorname{col}(A). Any AxAx with x=∑cizi+∑djwjx = \sum c_i z_i + \sum d_j w_j satisfies Ax=∑djAwjAx = \sum d_j Aw_j (the ziz_i are annihilated). So every column-space vector is a combination of the AwjAw_j.

Step 2: {Aw1,…,Awr}\{Aw_1, \dots, Aw_r\} is independent. Suppose ∑djAwj=0\sum d_j Aw_j = 0, i.e. A(∑djwj)=0A(\sum d_j w_j) = 0. Then v=∑djwj∈null⁡(A)v = \sum d_j w_j \in \operatorname{null}(A), so v=∑ciziv = \sum c_i z_i for some cic_i. But {z1,…,zk,w1,…,wr}\{z_1, \dots, z_k, w_1, \dots, w_r\} is a basis of Rn\mathbb{R}^n, so all coefficients are zero. Hence all dj=0d_j = 0.

Steps 1 and 2 together say {Aw1,…,Awr}\{Aw_1, \dots, Aw_r\} is a basis of col⁡(A)\operatorname{col}(A), confirming dim⁡col⁡(A)=r\dim\operatorname{col}(A) = r. The original basis of Rn\mathbb{R}^n had k+r=nk + r = n elements. ■\qquad\blacksquare

Solvability and solution structure

The system Ax=bAx = b is consistent if and only if b∈col⁡(A)b \in \operatorname{col}(A).

When it is consistent, the solution set is a coset of the null space: pick any particular solution xpx_p (i.e. Axp=bAx_p = b), then every solution has the form

x=xp+z,z∈null⁡(A).x = x_p + z, \qquad z \in \operatorname{null}(A).

Proof. If Ax=bAx = b and Axp=bAx_p = b, then A(x−xp)=0A(x - x_p) = 0, so x−xp∈null⁡(A)x - x_p \in \operatorname{null}(A). Conversely, A(xp+z)=b+0=bA(x_p + z) = b + 0 = b for any z∈null⁡(A)z \in \operatorname{null}(A). ■\qquad\blacksquare

In particular: if nullity⁡(A)=0\operatorname{nullity}(A) = 0 (the null space is just {0}\{0\}), the solution is unique when it exists. If nullity is positive, there are infinitely many.

Orthogonality of the four spaces

Row space and null space are orthogonal complements in Rn\mathbb{R}^n: every row- space vector is orthogonal to every null-space vector. The cleanest route to this is: if Ax=0Ax = 0 and yy is any row of AA, then y⋅x=0y \cdot x = 0 by definition. So the null space is perpendicular to every row, hence to the entire row space. By dimension count (row space has dimension rr, null space has dimension n−rn - r, and they are orthogonal), they are orthogonal complements. The same argument gives col space ⊥\perp left null space in Rm\mathbb{R}^m.

Check it on arrays

python · numpy
import numpy as np

A = np.array([
    [1.0, 2.0, 3.0],
    [2.0, 4.0, 6.0],   # row 2 = 2 * row 1
    [0.0, 1.0, 1.0],
], dtype=float)

r = np.linalg.matrix_rank(A)
n = A.shape[1]
print(f"rank={r}, nullity={n - r}, rank+nullity={n}")  # 2, 1, 3

# Null space via SVD (last right singular vectors for near-zero singular values):
_, s, Vt = np.linalg.svd(A)
print("singular values:", np.round(s, 6))  # one near zero
null_vec = Vt[-1]   # approximate null vector
print("A @ null_vec:", np.round(A @ null_vec, 10))   # ~zero

# Verify row space ⊥ null space:
# Row 0 should be orthogonal to null_vec
print("row0 . null_vec:", np.round(A[0] @ null_vec, 10))  # ~0

The near-zero singular value flags the one-dimensional null space; the null vector is numerically orthogonal to every row.

Exercises

Exercise 1. Let A=[123246]A = \begin{bmatrix} 1 & 2 & 3 \\ 2 & 4 & 6 \end{bmatrix}. Find the rank and nullity, and verify the rank-nullity theorem.

Solution

Step 1. Row 2 is 2×2 \times row 1, so the two rows are linearly dependent and there is exactly one independent row. Hence rank⁡(A)=1\operatorname{rank}(A) = 1.

Step 2. The matrix has n=3n = 3 columns, so rank-nullity gives nullity⁡(A)=n−rank⁡(A)=3−1=2\operatorname{nullity}(A) = n - \operatorname{rank}(A) = 3 - 1 = 2.

Step 3. Check directly: Ax=0Ax = 0 reduces to the single equation x1+2x2+3x3=0x_1 + 2x_2 + 3x_3 = 0 (row 2 is redundant). One linear constraint on three unknowns leaves a 22-dimensional solution space, matching nullity 22. The sum 1+2=3=n1 + 2 = 3 = n confirms the theorem.

Exercise 2. A matrix AA is 4×64 \times 6 with rank⁡(A)=4\operatorname{rank}(A) = 4. For how many right-hand sides b∈R4b \in \mathbb{R}^4 is Ax=bAx = b consistent, and when consistent, how many solutions does it have?

Solution

Step 1. Consistency. The column space lives in R4\mathbb{R}^4 and has dimension rank⁡(A)=4\operatorname{rank}(A) = 4, so col⁡(A)=R4\operatorname{col}(A) = \mathbb{R}^4. Every b∈R4b \in \mathbb{R}^4 is in the column space, so Ax=bAx = b is consistent for all bb.

Step 2. Count solutions. By rank-nullity, nullity⁡(A)=n−rank⁡(A)=6−4=2\operatorname{nullity}(A) = n - \operatorname{rank}(A) = 6 - 4 = 2, which is positive.

Step 3. When consistent, the solution set is the coset xp+null⁡(A)x_p + \operatorname{null}(A) from the lesson. A null space of dimension 22 contains infinitely many vectors, so there are infinitely many solutions for every bb.

Exercise 3 (code). Build a 5×45 \times 4 matrix whose 4th column is a fixed combination of the first three (so rank 33, nullity 11). Confirm the rank and nullity numerically, recover a null vector from the SVD, and verify it is orthogonal to every row of AA.

Solution

A column dependence forces nullity ≥1\ge 1; with three independent columns the rank is exactly 33. The null space is the orthogonal complement of the row space, so the null vector must be orthogonal to each row.

python · numpy
import numpy as np

rng = np.random.default_rng(0)
A = rng.normal(size=(5, 4))
A[:, 3] = 2.0 * A[:, 0] - A[:, 1]      # 4th column depends on cols 0 and 1

r = np.linalg.matrix_rank(A)
n = A.shape[1]
assert r == 3 and n - r == 1           # rank 3, nullity 1

# Null vector: right singular vector of the smallest singular value.
_, s, Vt = np.linalg.svd(A)
null_vec = Vt[-1]
assert np.allclose(A @ null_vec, 0, atol=1e-12)

# Row space is orthogonal to the null space: every row . null_vec == 0.
for row in A:
    assert abs(row @ null_vec) < 1e-10
print("rank:", r, "nullity:", n - r, "max |row . null|:",
      np.max(np.abs(A @ null_vec)))

The smallest singular value is numerically zero, flagging the one-dimensional null space, and Av=0A v = 0 states exactly that vv is orthogonal to every row of AA, the row-space/null-space orthogonality from the lesson.

The next lesson builds a ruler for measuring the length of vectors sitting in these spaces.


References

  1. [1]Strang, G. (2016). Introduction to Linear Algebra (5th ed.). Wellesley-Cambridge Press. The four fundamental subspaces and the equality of row and column rank.↩
  2. [2]Axler, S. (2015). Linear Algebra Done Right (3rd ed.), ch. 3. Springer. The rank-nullity theorem (fundamental theorem of linear maps) (doi:10.1007/978-3-319-11080-6).↩