The Rank-Nullity Theorem with Worked Examples

Every matrix encodes a linear transformation, and two numbers measure exactly how much that transformation does and undoes: its rank and its nullity. The rank-nullity theorem ties those numbers together in a strikingly clean equation, and understanding it gives you a mental model that makes many harder linear algebra results feel obvious.

The Statement

For any matrix A with n columns:

rank(A) + nullity(A) = n

The theorem is sometimes called the dimension theorem or the fundamental theorem of linear maps. It holds for every real (or complex) matrix, regardless of shape.

Pivot Columns and Free Variables

Row-reducing A to reduced row echelon form (RREF) partitions every column into one of two types.

A pivot column contains a leading 1; the corresponding variable is called a basic variable. The rank equals the number of pivot columns.

A non-pivot column has no leading entry; the corresponding variable is free to take any value. The nullity equals the number of free variables.

Since every column is either a pivot column or a non-pivot column, the two counts must add to n. That is the entire proof in one sentence. For a more formal treatment, see the discussion of free variables and basic variables and how they arise directly from RREF.

Why the Theorem Always Holds

Consider the linear map T: Rⁿ → Rᵐ defined by T(x) = Ax. The rank counts the dimension of the image (output space), and the nullity counts the dimension of the kernel (the set of inputs that map to zero).

Intuitively, each dimension of Rⁿ is either "used up" producing output (contributing to rank) or "collapsed" into zero (contributing to nullity). These are mutually exclusive -- a direction cannot simultaneously produce a nonzero output and be annihilated -- and they are exhaustive -- every input direction falls into one category. So rank and nullity partition the n available dimensions exactly.

Formally, the proof constructs a basis for the null space, extends it to a basis for all of Rⁿ, and shows that the added vectors map to a basis for the column space. The count works out to rank + nullity = n. You can read about the column space side of this in row space, column space, and null space.

Worked Example 1: A 3x5 Matrix

Let

A = | 1  2  0  1  3 |
    | 0  0  1  2  4 |
    | 0  0  0  0  0 |

This matrix is already in RREF. Count the pivot columns: column 1 (leading 1 in row 1) and column 3 (leading 1 in row 2). That gives rank(A) = 2.

The non-pivot columns are columns 2, 4, and 5, so there are 3 free variables: x₂, x₄, x₅. Therefore nullity(A) = 3.

Check:

rank(A) + nullity(A) = 2 + 3 = 5 = n ✓

To find an explicit basis for the null space, set each free variable to 1 while the others are 0:

Three basis vectors for the null space -- consistent with nullity 3. For the full procedure, see how to find a basis for the null space.

Worked Example 2: A 4x4 Matrix

Let

B = | 1  3  2  1 |
    | 2  6  5  3 |
    | 1  3  3  2 |
    | 0  0  1  1 |

Row-reduce to RREF. Subtracting 2R₁ from R₂ and R₁ from R₃:

| 1  3  2  1 |       | 1  3  2  1 |
| 0  0  1  1 |  -->  | 0  0  1  1 |
| 0  0  1  1 |       | 0  0  0  0 |
| 0  0  1  1 |       | 0  0  0  0 |

After R₃ - R₂ and R₄ - R₂:

| 1  3  0 -1 |
| 0  0  1  1 |
| 0  0  0  0 |
| 0  0  0  0 |

Pivot columns: column 1 and column 3. rank(B) = 2.

Free variables: x₂ and x₄. nullity(B) = 2.

Check:

rank(B) + nullity(B) = 2 + 2 = 4 = n ✓

Even though B is square and 4x4, it is singular -- the rank-nullity theorem immediately tells you the null space is 2-dimensional, so the system Bx = 0 has infinitely many solutions. To understand how rank connects to a matrix's invertibility, see how to find the rank of a matrix.

Practical Consequences

The theorem has direct applications beyond bookkeeping:

Consistency of linear systems. For Ax = b, solutions exist only when b is in the column space. The rank tells you the dimension of that column space, so it bounds how many right-hand sides are solvable.

Uniqueness of solutions. When nullity is zero, the only solution to Ax = 0 is the trivial one, which forces any solution to Ax = b to be unique. When nullity is positive, solutions come in families parameterized by the free variables.

Square matrices. For an n x n matrix, rank + nullity = n. Full rank (rank = n) forces nullity = 0, meaning the matrix is invertible. Any drop in rank produces an equally sized null space.

Dimension checks. If someone claims a matrix has rank 4 and nullity 3 with 6 columns, the theorem says that's impossible (4 + 3 = 7, not 6). It is a fast sanity check on any rank or nullity computation.

Frequently Asked Questions

Can rank(A) ever exceed the number of rows?

No. Rank equals the number of nonzero rows in RREF, so it is bounded by both the number of rows and the number of columns: rank(A) ≤ min(m, n) for an m x n matrix.

If nullity is zero, what does that mean geometrically?

It means the null space contains only the zero vector -- the transformation T(x) = Ax is injective (one-to-one). No two distinct inputs map to the same output. This can only happen when n ≤ m, because you need at least as many rows as columns to avoid free variables.

Does the theorem apply to non-square matrices?

Yes, without modification. A 3 x 7 matrix has n = 7 columns, so rank plus nullity always equals 7. Rank can be at most 3 (limited by the row count), which means nullity is at least 4.

How does nullity relate to the number of solutions of Ax = b?

When Ax = b is consistent and has one particular solution x_p, the complete solution is x_p + v for every v in the null space. So nullity directly counts the "degrees of freedom" in the solution set: nullity 0 means exactly one solution; nullity k means a k-dimensional affine family of solutions.