Visual Tools
Calculators
Tables
Mathematical Keyboard
Converters
Other Tools


Gaussian Elimination






The Workhorse Algorithm of Linear Algebra

Gaussian elimination transforms a linear system into a simpler equivalent form by systematically applying row operations. Forward elimination creates zeros below each pivot, producing row echelon form. Back substitution then solves from the bottom up. The algorithm handles every case — unique solutions, infinitely many solutions, and inconsistent systems — within a single unified framework.



The Goal

The input is an augmented matrix [Ab][A \mid \mathbf{b}] representing a linear system Ax=bA\mathbf{x} = \mathbf{b}. The output is an equivalent system — one with exactly the same solution set — in a form simple enough that the solution can be read off directly or obtained with minimal effort.

The "simple form" is echelon form: a staircase pattern where the leading entry of each row is to the right of the leading entry of the row above, and everything below each leading entry is zero. Once the augmented matrix is in echelon form, the solution is extracted by back substitution — solving from the last equation upward.

Optionally, the reduction can continue to reduced row echelon form (RREF), where each leading entry is 11 and is the only nonzero entry in its column. In RREF, the solution is visible by inspection.

The Three Elementary Row Operations

Gaussian elimination uses three operations, each of which transforms the augmented matrix without changing the solution set:

Elementary Row Operations
RiRj(swap)kRiRi,k0(scaling)Ri+cRjRi(addition)\begin{aligned} R_i &\leftrightarrow R_j \quad \text{(swap)} \\ kR_i &\to R_i, \quad k \neq 0 \quad \text{(scaling)} \\ R_i + cR_j &\to R_i \quad \text{(addition)} \end{aligned}

Row swap (RiRjR_i \leftrightarrow R_j): interchange two rows. This reorders the equations — a cosmetic change that is sometimes necessary to place a nonzero entry in the pivot position.

Row scaling (kRiRikR_i \to R_i, k0k \neq 0): multiply every entry in a row by a nonzero scalar. This rescales one equation. Multiplying by zero is forbidden because it would destroy information.

Row addition (Ri+cRjRiR_i + cR_j \to R_i): add cc times row jj to row ii, replacing row ii with the result. This is the operation that actually eliminates entries — by choosing cc appropriately, a targeted entry becomes zero.

Each operation is reversible: swapping the same pair undoes the swap, scaling by 1/k1/k undoes scaling by kk, and subtracting cc times row jj from row ii undoes the addition. Reversibility guarantees that no solutions are created or lost. Each operation also corresponds to left-multiplication by an elementary matrix, connecting the algorithm to the theory of matrix factorization.
Operation Notation Effect on the system Reverse operation
Row swap Ri ↔ Rj reorders two equations; used to place a nonzero entry into the pivot position the same swap Ri ↔ Rj
Row scaling k · Ri → Ri  (k ≠ 0) rescales one equation; used to make pivots equal to 1 in RREF scaling the same row by 1 / k
Row addition Ri + c · Rj → Ri replaces one equation by a combination; this is the operation that actually eliminates entries Ri − c · Rj → Ri

Elimination Notation

Notation

Elimination Notation

The bar that keeps a system from being just a matrix, the arrow that must point at the right row, and the tilde that says “same solutions, different entries.”
Matrices and their entries — matrix notation; bold x\mathbf{x}, b\mathbf{b}vector notation; RiRjR_i \leftrightarrow R_j, kRiRikR_i \to R_i, Ri+cRjRiR_i + cR_j \to R_i are defined in The Three Elementary Row Operations above.
[Ab][A \mid \mathbf{b}]
The augmented matrix — A, bar, b
The vertical bar is punctuation, not an operation: left of it, coefficient columns; right of it, the constants. The bar records where the == signs of the original system stood, and it rides along unchanged through every row operation.
CasesErase the bar and the object changes species — from a record of a system to a plain m×(n+1)m \times (n{+}1) matrix. Multiple right-hand sides stack more columns behind the bar: [Ab1  b2][A \mid \mathbf{b}_1 \; \mathbf{b}_2], the device that computes an inverse via [AI][A \mid I].
Also written(Ab)(A \mid \mathbf{b}) with parentheses, matching this site's matrix brackets; some texts drop the bar entirely and trust the reader's memory — the bar exists so nobody has to.
Do not confuseA determinant or divisibility bar. The single upright stroke has many jobs; between matrix columns inside brackets it only ever separates.
Ri+cRjRiR_i + cR_j \to R_i
Row i plus c times row j, replacing row i
The arrow points at the row being replaced — that is the entire convention, and the entire hazard. In every legal addition step, the row that survives unscaled is the one being written over; row jj is only read, never changed.
CasesTexts disagree on the spelling: RiRi+cRjR_i \to R_i + cR_j (arrow first), Ri:=Ri+cRjR_i := R_i + cR_j (assignment), Ri=Ri+cRjR_i' = R_i + cR_j (primes). Same operation throughout — but the illegal move cRjRicR_j \to R_i, overwriting a row with a multiple of another, destroys information and no notation makes it legal.
Also writtenAnnotations over a long arrow between displayed matrices — R23R1\xrightarrow{R_2 - 3R_1} — the compact form worked examples use.
Do not confuseThe limit arrow. Same glyph as approach; here it means “becomes” — an update, not a tendency.
ABA \sim B
A is row-equivalent to B
The tilde asserts that a chain of row operations connects AA to BB — entries differ, solution sets agree. It is precisely not equality: writing == between elimination steps is the classic false statement, because the matrices are genuinely different.
CasesEvery elimination chain is a chain of tildes ending in echelon form; the tilde is what licenses reading the final matrix's solutions as the first matrix's.
Also written\rightarrow between displayed matrices, arrow standing in for the tilde in worked examples — including this page's.
Do not confuseThe tilde's other lives: equivalent sets in set theory, “is distributed as” in statistics, \approx's single-stroke cousin for approximation. One squiggle, four fields, four meanings.

Forward Elimination

Forward elimination is the first phase of the algorithm. It sweeps through the augmented matrix from left to right, top to bottom, creating zeros below each pivot.

Start with the leftmost column that contains a nonzero entry. Identify a nonzero entry in that column to serve as the pivot — if the entry in the current top row is zero, swap that row with a row below that has a nonzero entry in this column. Then use row addition to eliminate every entry below the pivot: for each row ii below the pivot row, add aijapj-\frac{a_{ij}}{a_{pj}} times the pivot row to row ii, zeroing out the (i,j)(i, j) entry.

Move one column to the right and one row down, and repeat the process on the submatrix below and to the right of the current pivot. Continue until no rows or columns remain to process.

The result is a matrix in row echelon form: a staircase of pivots descending from upper-left to lower-right, with zeros filling in below and to the left of each pivot. Any rows that are entirely zero sit at the bottom.
120.504.5002140−12.503.50
Clearing one entry beneath a pivot

A multiple of the pivot row is being subtracted from the row below to put a zero under the pivot. Nothing about the solution set changes, because the operation is reversible — the same multiple added back restores the original. That reversibility is the licence for the whole algorithm. Step through a full elimination on the Gaussian elimination visualizer.

Every step of forward elimination is one instance of this move, applied downward and then leftward across the matrix.

Pivots and Pivot Positions

A pivot is the leading (leftmost) nonzero entry in each row of the echelon form. The column containing a pivot is a pivot column; every other column is a free column.

The number of pivots equals the rank of the coefficient matrix. Pivot columns correspond to determined variables (pivot variables) whose values are fixed once the free variables are assigned. Free columns correspond to free variables (parameters) that can take any real value.

If every column of AA is a pivot column, the system has no free variables and the solution (if it exists) is unique. If at least one column is free, the solution set (if nonempty) is infinite, parametrized by the free variables. The distinction between pivot and free columns is the structural core of the algorithm — it determines both the form and the dimension of the solution set.

Back Substitution

Once the augmented matrix is in row echelon form, the solution is obtained by solving from the bottom row upward.

The last nonzero row contains the fewest unknowns — typically one pivot variable in terms of free variables and a constant. Solve for that pivot variable. Substitute the result into the row above, which now also becomes solvable for its pivot variable. Continue upward until every pivot variable is expressed in terms of the free variables and the constants from b\mathbf{b}.

Worked Example


(2139042600510)\left(\begin{array}{ccc|c} 2 & -1 & 3 & 9 \\ 0 & 4 & -2 & 6 \\ 0 & 0 & 5 & 10 \end{array}\right)


The bottom row gives 5x3=105x_3 = 10, so x3=2x_3 = 2. The middle row gives 4x22(2)=64x_2 - 2(2) = 6, so 4x2=104x_2 = 10 and x2=5/2x_2 = 5/2. The top row gives 2x15/2+3(2)=92x_1 - 5/2 + 3(2) = 9, so 2x1=9+5/26=11/22x_1 = 9 + 5/2 - 6 = 11/2 and x1=11/4x_1 = 11/4.

Each step required only previously solved variables. The process terminates in nn steps, with the solution fully determined.

Gauss-Jordan Elimination

Gauss-Jordan elimination extends the forward pass with a backward pass that creates zeros above each pivot as well, and scales each pivot to 11. The result is reduced row echelon form (RREF), where every pivot variable is already isolated in its row.

After forward elimination produces REF, continue by working from the bottom pivot upward. For each pivot, add appropriate multiples of its row to the rows above to eliminate all entries above the pivot. Then scale the pivot row so the pivot entry becomes 11.

The payoff is that in RREF, the solution is visible by direct inspection — no back substitution is needed. Each pivot row reads "xi=(expression in free variables and constants)x_i = \text{(expression in free variables and constants)}." The trade-off is that the backward pass requires additional row operations, roughly doubling the total work compared to forward elimination alone.

For hand computation, the choice between back substitution (stop at REF) and Gauss-Jordan (continue to RREF) is a matter of preference. For computer implementations, both approaches are standard.
1001.420101.080011.83
Reduced row echelon form reached

Pivots have been scaled to one and cleared above as well as below, so each pivot column now holds a single one and nothing else. At this point no back substitution is left: the values are sitting in the final column. Compare the effort against stopping at echelon form on the Gaussian elimination visualizer.

Whether the extra clearing is worth it depends entirely on whether you want the answer or the structure.

Worked Example: Unique Solution

Solve the system

x1+2x2x3=3,2x1+5x2+x3=8,3x1+8x2+2x3=13x_1 + 2x_2 - x_3 = 3, \quad 2x_1 + 5x_2 + x_3 = 8, \quad 3x_1 + 8x_2 + 2x_3 = 13


Form the augmented matrix and apply forward elimination:

(1213251838213)R22R1,  R33R1(121301320254)\left(\begin{array}{ccc|c} 1 & 2 & -1 & 3 \\ 2 & 5 & 1 & 8 \\ 3 & 8 & 2 & 13 \end{array}\right) \xrightarrow{R_2 - 2R_1,\; R_3 - 3R_1} \left(\begin{array}{ccc|c} 1 & 2 & -1 & 3 \\ 0 & 1 & 3 & 2 \\ 0 & 2 & 5 & 4 \end{array}\right)


R32R2(121301320010)\xrightarrow{R_3 - 2R_2} \left(\begin{array}{ccc|c} 1 & 2 & -1 & 3 \\ 0 & 1 & 3 & 2 \\ 0 & 0 & -1 & 0 \end{array}\right)


Three pivots in three columns — unique solution. Back substitution: row 33 gives x3=0-x_3 = 0, so x3=0x_3 = 0. Row 22 gives x2+3(0)=2x_2 + 3(0) = 2, so x2=2x_2 = 2. Row 11 gives x1+2(2)0=3x_1 + 2(2) - 0 = 3, so x1=1x_1 = -1.

Verification: 1+40=3-1 + 4 - 0 = 3, 2+10+0=8-2 + 10 + 0 = 8, 3+16+0=13-3 + 16 + 0 = 13. All three equations are satisfied.

Worked Example: Infinitely Many Solutions

Solve the system

x1x2+2x3+x4=3,2x12x2+5x3+4x4=8x_1 - x_2 + 2x_3 + x_4 = 3, \quad 2x_1 - 2x_2 + 5x_3 + 4x_4 = 8


Two equations in four unknowns — more unknowns than equations, so the solution (if it exists) cannot be unique. Form and reduce:

(1121322548)R22R1(1121300122)\left(\begin{array}{cccc|c} 1 & -1 & 2 & 1 & 3 \\ 2 & -2 & 5 & 4 & 8 \end{array}\right) \xrightarrow{R_2 - 2R_1} \left(\begin{array}{cccc|c} 1 & -1 & 2 & 1 & 3 \\ 0 & 0 & 1 & 2 & 2 \end{array}\right)


Pivots in columns 11 and 33. Columns 22 and 44 are free. Let x2=sx_2 = s and x4=tx_4 = t. Row 22 gives x3=22tx_3 = 2 - 2t. Row 11 gives x1=3+s2(22t)t=1+s+3tx_1 = 3 + s - 2(2 - 2t) - t = -1 + s + 3t.

The general solution in parametric vector form:

x=(1020)+s(1100)+t(3021)\mathbf{x} = \begin{pmatrix} -1 \\ 0 \\ 2 \\ 0 \end{pmatrix} + s\begin{pmatrix} 1 \\ 1 \\ 0 \\ 0 \end{pmatrix} + t\begin{pmatrix} 3 \\ 0 \\ -2 \\ 1 \end{pmatrix}


The solution set is a two-dimensional plane in R4\mathbb{R}^4, passing through (1,0,2,0)(-1, 0, 2, 0) and spanned by two direction vectors.

Worked Example: No Solution

Solve the system

x1+x2=2,2x1+2x2=3x_1 + x_2 = 2, \quad 2x_1 + 2x_2 = 3


Form and reduce:

(112223)R22R1(112001)\left(\begin{array}{cc|c} 1 & 1 & 2 \\ 2 & 2 & 3 \end{array}\right) \xrightarrow{R_2 - 2R_1} \left(\begin{array}{cc|c} 1 & 1 & 2 \\ 0 & 0 & -1 \end{array}\right)


The second row reads 0x1+0x2=10x_1 + 0x_2 = -1, which is the equation 0=10 = -1. This is a contradiction — no values of x1x_1 and x2x_2 can satisfy it.

The system is inconsistent. Geometrically, the two equations represent parallel lines in R2\mathbb{R}^2: x1+x2=2x_1 + x_2 = 2 and x1+x2=3/2x_1 + x_2 = 3/2 (the second equation, after dividing by 22). Parallel lines with different intercepts never intersect.

Inconsistency is always detectable in echelon form: a row [0  0    0d][0 \; 0 \; \cdots \; 0 \mid d] with d0d \neq 0 means rank([Ab])>rank(A)\text{rank}([A \mid \mathbf{b}]) > \text{rank}(A), and by the Rouché-Capelli theorem, no solution exists.
000000000000
A row of zeros against a non-zero constant

The coefficients in this row have all been eliminated while the constant has not, so the row now asserts that zero equals something non-zero. One such row is enough to make the entire system inconsistent, regardless of how well the other rows behaved. Construct one deliberately on the Gaussian elimination visualizer.

Inconsistency is therefore detected, not decided — it announces itself as a row rather than having to be tested for.

Computational Cost

Forward elimination on an n×nn \times n system requires roughly 23n3\frac{2}{3}n^3 arithmetic operations (multiplications and additions). The cost comes from the nested loop structure: for each of the nn pivot columns, elimination involves O(n)O(n) rows, each requiring O(n)O(n) operations.

Back substitution requires roughly n2n^2 operations — a negligible addition compared to forward elimination. Gauss-Jordan elimination (continuing to RREF) raises the total to roughly n3n^3, because the backward pass does comparable work to the forward pass.

These costs are dramatically better than the alternatives for large systems. Cramer's rule requires n+1n + 1 determinant evaluations, each costing O(n3)O(n^3) via row reduction or O(n!)O(n!) via cofactor expansion — orders of magnitude slower. Computing the inverse explicitly costs roughly 2n32n^3 operations. Gaussian elimination is the standard baseline against which all other direct methods are measured.
Phase or method (n × n system) Approximate operation count Comment
Forward elimination (produces REF) ~ (2/3) n³ dominant cost of Gaussian elimination
Back substitution after REF ~ n² negligible compared to forward elimination
Gauss-Jordan (forward + backward to RREF) ~ n³ backward pass roughly doubles the forward pass
Computing A⁻¹ explicitly, then x = A⁻¹b ~ 2 n³ roughly 3× the cost of direct elimination
Cramer's rule (n + 1) determinants, each O(n³) via row reduction orders of magnitude slower than elimination for large n; cofactor-expansion routes are O(n!), astronomically slow

Partial Pivoting

In exact arithmetic, any nonzero entry can serve as a pivot. In floating-point arithmetic, the choice matters. A very small pivot amplifies rounding errors — dividing by a number close to zero magnifies any imprecision in the numerator.

Partial pivoting addresses this by modifying the pivot selection step. At each stage, instead of using whatever nonzero entry happens to sit in the pivot position, the algorithm scans the entries below (and including) the current position in the pivot column and swaps the row with the largest absolute value into the pivot position. This keeps the multipliers aij/apj-a_{ij}/a_{pj} small, which limits the accumulation of rounding error.

Partial pivoting does not change the mathematical structure of Gaussian elimination — it only changes which row swaps are performed. The echelon form, the rank, the pivots, and the solution are all the same in exact arithmetic. The difference is entirely numerical: partial pivoting makes the computation stable.

Every serious numerical implementation of Gaussian elimination uses partial pivoting by default. In the LU decomposition, the row swaps are recorded in a permutation matrix PP, giving the factorization PA=LUPA = LU.

Summary: The Algorithm at a Glance

Gaussian elimination splits cleanly into a small number of stages — preparing the augmented matrix, reducing it forward, classifying columns as pivot or free, and reading the solution by back substitution or Gauss-Jordan. The table below collects each stage alongside what happens in it and what the next step receives as input, providing a single-page workflow card for the procedure.
The stages below are not all of the same kind. The first two happen for every system and in that order; the third is a fork, where two different amounts of work lead to the same solution set. Separating the compulsory part from the choice is what makes the cost comparison meaningful — the elimination is paid either way, and only the reading differs.
Linear systems · the algorithm

Gaussian elimination, stage by stage

Two stages are compulsory and the third is a choice. Forward elimination and classification happen once; after that, back substitution and Gauss–Jordan reach the same solution set by different amounts of work.

5stages
Compulsory — every system, every time2
1
swaps and row additions, left to right
[Ab][A \mid \mathbf{b}] \to row echelon form
Sweep column by column, using each pivot to zero everything beneath it. This is the expensive stage at roughly 23n3\tfrac{2}{3}n^3 operations, and it is where partial pivoting belongs — choosing the largest available pivot rather than the first nonzero one.
2
and check for [00d0][\,0 \cdots 0 \mid d \neq 0\,]
pivot columns vs free columns
Everything diagnostic happens here. The pivot count is the rank, the free columns are the parameters, and a contradiction row settles solvability before any solution is attempted.
A choice — two ways to read the answer2
3
solve upward from the last pivot row
Less arithmetic: roughly n2n^2 operations on top of the elimination, and no further row operations at all. The usual choice by hand and the one every numerical library uses, since the triangular form is already enough to solve from.
4
zero above the pivots, scale pivots to 11
continue to reduced row echelon form
Roughly 50%50\% more arithmetic than back substitution for the same solution, so it is not the method of choice for solving. Its value is elsewhere: the RREF is unique, which makes it the right form for reading a null space basis or inverting a matrix.
What comes out1
5
decided at the classification stage
a point, or xp+Null(A)\mathbf{x}_p + \operatorname{Null}(A), or empty
Never anything else. Unique when every column has a pivot, a translated subspace when some do not, empty when a contradiction row appeared — and which of the three it is was known before the solution was computed.
The whole algorithm is three row operations applied until the shape is triangular, and every one of them is reversible — which is why the solution set is unchanged at every step. Elimination does not solve the system so much as rewrite it into a form where the solution can be read.
Gaussian elimination, stage by stage·/linear-algebra/linear-systems/gaussian-eliminationLearn Math Class
The classification stage is the one most easily skipped and the one that carries the most. Before any solution is written down, the pivot positions already give the rank, the free columns already give the number of parameters, and a contradiction row already settles that there is no solution at all. Work done after that point is filling in a shape that has already been determined.
Between the two readings, back substitution wins on arithmetic and Gauss–Jordan wins on form. Continuing to the reduced row echelon form costs roughly half again as much for the same answer, which is a poor trade if solving is the goal. It is the right trade when the form is the goal — the RREF is unique where the REF is not, so it is what a null space basis, a matrix inverse, or a comparison between two matrices has to be read from.

Gaussian Elimination FAQ

What is the bar doing in [Ab][A \mid \mathbf{b}]?

+
Separating, nothing more. It marks the array as a record of a system rather than a plain matrix, and erasing it changes the object's species into an ordinary m×(n+1)m \times (n{+}1) matrix. The same device stacks more columns behind the bar for multiple right-hand sides, which is how [AI][A \mid I] computes an inverse.Read more →

Can you overwrite a row with a multiple of a different row?

+
No, and no notation makes it legal. The valid replacement keeps the target row in the expression, as in RiRi+cRjR_i \to R_i + cR_j, so the operation is reversible. Writing cRjRicR_j \to R_i discards whatever RiR_i contained, destroying information the system needed and producing a matrix that is not row-equivalent to the original.Read more →

Does the tilde in ABA \sim B mean approximately equal?

+
Not here, where it means row-equivalent: one matrix reaches the other through elementary row operations, so both describe the same solution set. The squiggle leads several lives across mathematics, marking equivalent sets in set theory and "is distributed as" in statistics, besides its single-stroke role as a cousin of the approximation sign.Read more →