CipherMatrix

Matrix Operations and Rank Calculator

Add, subtract, multiply, scale and transpose matrices of any size, then find the rank, row echelon form (REF) and reduced row echelon form (RREF) with every row operation explained.

Matrix operations this calculator supports

Matrices do not have to be square. You can enter any size from 1×1 up to 8×8, including rectangular shapes such as 2×3, 3×2 or 4×3, and the calculator tells you immediately when an operation is not defined for the sizes you chose.

  • Addition and subtraction work entry by entry and need two matrices of exactly the same size.
  • Multiplication A·B needs the number of columns of A to equal the number of rows of B; an m×n matrix times an n×p matrix gives an m×p matrix.
  • Scalar multiplication multiplies every entry by one number k.
  • Transpose turns rows into columns, so an m×n matrix becomes n×m.
  • Rank, REF and RREF use Gaussian elimination and Gauss–Jordan elimination.

How matrix multiplication works

Each entry of the product is a dot product: cij = ai1b1j + ai2b2j + … + ainbnj. In words, take row i of A and column j of B, multiply matching entries and add. The calculator writes out every one of these sums. Remember that matrix multiplication is generally not commutative: A·B and B·A are usually different, and one of them may not even exist.

Rank, REF and RREF in one idea

Gaussian elimination uses three row operations that never change the rank: swap two rows, multiply a row by a non-zero number, and add a multiple of one row to another. Working column by column from the left, we pick a pivot, make it 1 and clear the entries below it. The result is the row echelon form (REF). Clearing the entries above each pivot as well gives the reduced row echelon form (RREF), which is unique for every matrix.

The rank of a matrix is the number of pivots, which equals the number of non-zero rows in REF. It is the dimension of the row space and of the column space, and by the rank–nullity theorem the nullity is the number of columns minus the rank.

Why exact fractions matter

Floating-point elimination can turn a true zero into a tiny non-zero number such as 1e-16 and report the wrong rank. This calculator uses exact rational arithmetic, so zeros are exactly zero and the rank is always correct. Inputs can be integers, decimals such as 0.25 or fractions such as 1/3.

Worked examples

These examples are computed by the same engine as the calculator above, so you can compare each step with your own working.

Multiplying a 2×3 matrix by a 3×2 matrix

A × B
result 2×2

Step-by-step solution

Formula used
C = A·B
cᵢⱼ = Σₖ aᵢₖ·bₖⱼ (row i of A times column j of B)
Requirement: columns of A = rows of B, (m×n)·(n×p) = (m×p).
  1. NoteCheck dimensions
    (2×3)·(3×2) → 2×2
    Columns of A = 3 = rows of B, so the product is defined.
    C will be 2×2 and needs 4 entries (3 multiplications each).
  2. PivotExample: c₁₁ = (row 1 of A) · (column 1 of B)
    c₁₁ = a₁₁b₁₁ + a₁₂b₂₁ + a₁₃b₃₁
    Highlighted: the row of A and the column of B that are multiplied entry by entry and then added.
    A =123456B =789101112
  3. Row additionRow × column for every entry
    cᵢⱼ = aᵢ₁b₁ⱼ + aᵢ₂b₂ⱼ + … + aᵢₙbₙⱼ
    c₁₁ = a₁₁b₁₁ + a₁₂b₂₁ + a₁₃b₃₁ = (1)(7) + (2)(9) + (3)(11) = 7 + 18 + 33 = 58
    c₁₂ = a₁₁b₁₂ + a₁₂b₂₂ + a₁₃b₃₂ = (1)(8) + (2)(10) + (3)(12) = 8 + 20 + 36 = 64
    c₂₁ = a₂₁b₁₁ + a₂₂b₂₁ + a₂₃b₃₁ = (4)(7) + (5)(9) + (6)(11) = 28 + 45 + 66 = 139
    c₂₂ = a₂₁b₁₂ + a₂₂b₂₂ + a₂₃b₃₂ = (4)(8) + (5)(10) + (6)(12) = 32 + 50 + 72 = 154
  4. NoteIntermediate matrix (sums of products, not yet evaluated)
    C =(1)(7) + (2)(9) + (3)(11)(1)(8) + (2)(10) + (3)(12)(4)(7) + (5)(9) + (6)(11)(4)(8) + (5)(10) + (6)(12)
  5. ResultEvaluate every entry → product matrix
    C =5864139154

Rank of a singular 3×3 matrix

rank(A) = 2
rank = 2

Step-by-step solution

Formula used
Row operations: Rᵢ ↔ Rⱼ (swap), Rᵢ ← k·Rᵢ (k ≠ 0), Rᵢ ← Rᵢ + k·Rⱼ (add a multiple).
Elimination factor: Rᵢ ← Rᵢ - (aᵢc / pivot)·R_pivot, which makes aᵢc = 0.
rank(A) = number of pivots (nonzero rows) of a row echelon form of A.
REF here scales each pivot to 1; different valid row-operation orders give different REFs, but the rank and the RREF are always the same.
  1. StartStart with the original matrix
    A is 3×3. Work column by column from left to right. The current pivot row is called r (starting at row 1).
    Allowed row operations (they never change the rank): swap two rows, multiply a row by a nonzero number, add a multiple of one row to another.
    123456789
  2. PivotPivot selection (column 1)
    pivot = a₁₁ = 1
    Scan column 1 from row 1 downward: the first nonzero entry is a₁₁ = 1 (row 1). It already sits in the pivot position (1, 1).
    123456789
  3. Row additionElimination below the pivot (column 1)
    R₂ ← R₂ - 4·R₁
    Goal: turn a₂₁ = 4 into 0 using the pivot row R₁. (R₂ ← R₂ - (4)·R₁)
    new R₂ = [4, 5, 6] - (4)·[1, 2, 3] = [0, -3, -6]
    1230−3−6789
  4. Row additionElimination below the pivot (column 1)
    R₃ ← R₃ - 7·R₁
    Goal: turn a₃₁ = 7 into 0 using the pivot row R₁. (R₃ ← R₃ - (7)·R₁)
    new R₃ = [7, 8, 9] - (7)·[1, 2, 3] = [0, -6, -12]
    1230−3−60−6−12
  5. PivotPivot selection (column 2)
    pivot = a₂₂ = -3
    Scan column 2 from row 2 downward: the first nonzero entry is a₂₂ = -3 (row 2). It already sits in the pivot position (2, 2).
    1230−3−60−6−12
  6. Row multiplyRow multiplication
    R₂ ← (-1/3)·R₂
    Divide row 2 by the pivot -3 (multiply by 1/(-3) = -1/3) so the pivot becomes 1.
    new R₂ = [0, -3, -6] · (-1/3) = [0, 1, 2]
    1230120−6−12
  7. Row additionElimination below the pivot (column 2)
    R₃ ← R₃ + 6·R₂
    Goal: turn a₃₂ = -6 into 0 using the pivot row R₂. (R₃ ← R₃ - (-6)·R₂)
    new R₃ = [0, -6, -12] - (-6)·[0, 1, 2] = [0, 0, 0]
    123012000
  8. No pivotColumn 3: no pivot
    Every entry of column 3 from row 3 downward is 0, so this column has no pivot. Move one column to the right (the pivot row stays at R₃).
    123012000
  9. ResultRow echelon form (REF) reached
    Each pivot is 1, each pivot lies to the right of the pivot above it, and everything below a pivot is 0.
    Number of pivots = 2; the last 1 row(s) are all zeros.
    123012000
  10. ResultFinal answer
    Pivot positions: (1, 1), (2, 2)
    Pivot columns: 1, 2
    rank(A) = 2 (number of pivots = number of nonzero rows)
    nullity(A) = n - rank = 3 - 2 = 1 (rank-nullity theorem)
    Always rank(A) <= min(m, n) = min(3, 3) = 3.
    A is square with rank < n, so det(A) = 0: A is singular (not invertible).
    REF(A) =123012000

Frequently asked questions

Can I multiply matrices of different sizes?

Yes, as long as the number of columns of the first matrix equals the number of rows of the second. A 2×3 matrix times a 3×4 matrix is a 2×4 matrix, but a 2×3 matrix times a 2×3 matrix is not defined.

What is the difference between REF and RREF?

REF only requires zeros below each pivot (and, in this calculator, pivots equal to 1). RREF also requires zeros above each pivot, so every pivot is the only non-zero entry in its column. The RREF of a matrix is unique; a REF is not.

How do I find the rank of a matrix?

Reduce the matrix to row echelon form and count the pivots (non-zero rows). The rank can never exceed the smaller of the number of rows and columns.

What is the rank of a zero matrix?

Zero. A zero matrix has no pivots, so its rank is 0.

Does the calculator work for non-square matrices?

Yes. Rank, REF, RREF, addition, multiplication (when the sizes match), scalar multiplication and transpose all work for rectangular matrices.

Related calculators