The idea: doing A and then B is one matrix, B·A

Every 2×2 matrix moves the plane: it sends each point v to A·v. If you move the plane with A and then move the result with B, every point ends at B(A·v). That two-step move is again a linear map, so it has a matrix of its own, and that matrix is the product B·A. This is called the composition of the two maps.

Three panels with the letter F. Middle: the start. Left: rotate 90° first, then shear k = 1, giving H·R = [1 −1; 1 0]. Right: shear first, then rotate 90°, giving R·H = [0 −1; 1 1]. The two final F's point in different directions
Rotate then shear and shear then rotate start from the same F and end in different places: H·R ≠ R·H.

Watch the order of the letters. The transform that acts first is written on the right, because it is the one next to v: in B·A·v, the vector meets A first. Read a product from right to left. On the canvas, pick "first A" and "then B": the grid moves by A, then by B, and the product panel works out B·A.

Row times column

Each entry of B·A is a row of B times a column of A: multiply entry by entry and add. With A = rotate 90° = [0 −1; 1 0] and B = shear = [1 1; 0 1]:

[1101][0−110]=[1·0+1·11·(−1)+1·00·0+1·10·(−1)+1·0]=[1−110]

The columns of the answer are where î and ĵ end up after both moves: î goes to (0, 1) under the rotation, and the shear moves (0, 1) to (1, 1). That is column 1 of B·A. Column j of B·A is B times column j of A. The full rule for bigger matrices is on Matrix Multiplication.

Order matters, AB ≠ BA

Swap the two and you get a different matrix: rotate 90° after the shear gives R·H = [0 −1; 1 1], not [1 −1; 1 0]. The two end pictures differ. The Swap order button keeps the first end picture in grey and runs the other order from the start, so you can see the blue F land somewhere else (Demo: rotate then shear vs shear then rotate).

Some pairs do commute (AB = BA):

PairCommutes?Why
two rotations about 0✓ yesthe angles add: 45° + 90° = 90° + 45° = 135°
two scalings along the axes✓ yesdiagonal matrices: [a 0; 0 b][c 0; 0 d] = [ac 0; 0 bd]
any map and itself, any map and I✓ yesA·A = A·A, A·I = I·A = A
rotation and shear✗ noH·R ≠ R·H above
two different reflections✗ noone order turns +2α, the other −2α
scale x and rotate 90°✗ nothe stretch lands on x or on y

Two rotations about the origin always commute (Demo: two rotations: order doesn't matter): after Swap order the blue grid lands exactly on the grey one. See Rotation Matrix and Scaling Matrix.

Two reflections make a rotation

A reflection flips the plane over a mirror line. Flip twice and the two flips cancel: the result keeps orientation, so it is a rotation. Its angle is twice the angle between the mirrors, turning from the first mirror toward the second. Reflect in the x-axis (0°) and then in the line y = x (45°): the result is the rotation by 2·45° = 90° (Demo: two reflections make a rotation):

[0110][100−1]=[0−110]=R(90°)
An F reflected first in the x-axis (mirror at 0°), then in the line y = x (mirror at 45°). The final F is the start F turned 90° counter-clockwise; the angle between the mirrors is 45°
Two mirrors 45° apart: flip, flip again, and the F has turned by 2·45° = 90°.

In the other order (first y = x, then the x-axis) the turn goes the other way, −90°. A reflection followed by a rotation, or the other way round, is again a reflection.

Determinants multiply

The determinant is the factor by which a map changes areas, with a minus sign when it flips orientation. Two maps in a row multiply the area factors, so det(BA) = det B · det A (Demo: det multiplies).

first Athen Bdet Adet Bdet(BA)what happens to area
scale x by 2reflect in x-axis2−1−2doubled and flipped
reflect in x-axisreflect in y = x−1−11two flips cancel: a rotation
rotate 90°shear k = 1111area kept
project onto x-axisrotate 90°010flat: area 0, for good

Because det B · det A = det A · det B, the two orders always have the same determinant even when AB ≠ BA: same area factor, different map.

Undo in reverse order: socks and shoes

You put on socks, then shoes. To undo that you take off the shoes first, then the socks. Matrices work the same way: the inverse of B·A is

(BA)−1=A−1B−1,A−1B−1BA=A−1IA=I

B went on last, so B⁻¹ acts first; A⁻¹ acts last and is written on the left. The Undo (reverse order) button does exactly that: the grid moves by B⁻¹ back to A's picture, then by A⁻¹ back to the plain grid (Demo: undo in reverse order (socks and shoes)). The wrong order, B⁻¹A⁻¹, does not get back unless A and B commute.

Top row: I, then A (socks), then B (shoes), ending at BA. Bottom row, going back: from BA, B⁻¹ first (shoes off), then A⁻¹ (socks off), back to I
On: A, then B. Off: B⁻¹ first, then A⁻¹, so (BA)⁻¹ = A⁻¹B⁻¹.

If either map has det 0, the product has det 0 too and nothing can undo it. A projection sends a whole line of points to one point, and no matrix can tell them apart again (Demo: a projection can't be undone).

See also the overview Linear Transformations, the single transforms Rotation Matrix, Reflection Matrix, Scaling Matrix, Shear Matrix and Projection Matrix, Inverse Matrix, Affine Transforms (composing moves that include a translation), Rotate and Translate in 2D, Diagonalization (A = PDP⁻¹, a composition of three maps) and SVD and PCA (every matrix is rotate, stretch, rotate).

What the page leaves out

Only seven fixed 2×2 maps and pairs of them are drawn. Chains of three or more (the product is associative: (CB)A = C(BA), so the brackets never matter, only the order), composing with translations (they need 3×3 homogeneous matrices, see Affine Transforms), 3D compositions such as yaw-pitch-roll rotations, rotations about different centers, and the group structure (rotations form a group that commutes in 2D but not in 3D) are not shown.