Ray diagrams show where an image is. The mirror equation says exactly where, and it is a rational equation you solve by working with reciprocals.
Key idea
$$\frac{1}{f} = \frac{1}{d_o} + \frac{1}{d_i}, \qquad m = -\frac{d_i}{d_o} = \frac{h_i}{h_o}.$$ Signs: real is positive. $d_o > 0$ for a real object; $d_i > 0$ for a real image (in front of the mirror) and $d_i < 0$ for a virtual one (behind); $f > 0$ for concave and $f < 0$ for convex. $m < 0$ means inverted.
Why it works
Draw the ray that hits the center of the mirror: it reflects at equal angles, making two similar triangles, so $\frac{h_i}{h_o} = -\frac{d_i}{d_o}$ (the minus because the image is inverted). The parallel ray reflects through $F$ and makes two more similar triangles: $\frac{h_i}{h_o} = -\frac{d_i - f}{f}$. Set the two equal, $\frac{d_i}{d_o} = \frac{d_i - f}{f}$, and divide through by $d_i$: $\frac{1}{d_o} = \frac{1}{f} - \frac{1}{d_i}$. That is the mirror equation.
Common mistake
Dropping the sign convention, for example giving a convex mirror a positive focal length. A convex mirror always has $f < 0$, and then $d_i$ always comes out negative: a virtual image behind the mirror. Check: if you get a real image from a convex mirror, a sign slipped.
Worked example: Concave mirror, real image
An object is $30\ \text{cm}$ from a concave mirror with $f = 12\ \text{cm}$. Find the image distance and magnification.
- $\dfrac{1}{d_i} = \dfrac{1}{12} - \dfrac{1}{30} = \dfrac{5}{60} - \dfrac{2}{60} = \dfrac{3}{60}$.
- $d_i = 20\ \text{cm}$: positive, so real, in front of the mirror.
- $m = -\dfrac{20}{30} = -0.67$: inverted and two-thirds the size.
Answer: $d_i = 20\ \text{cm}$, $m = -0.67$
Worked example: Concave mirror, virtual image
An object is $10\ \text{cm}$ from a concave mirror with $f = 20\ \text{cm}$.
- $\dfrac{1}{d_i} = \dfrac{1}{20} - \dfrac{1}{10} = -\dfrac{1}{20}$, so $d_i = -20\ \text{cm}$.
- Negative: a virtual image $20\ \text{cm}$ behind the mirror.
- $m = -\dfrac{-20}{10} = +2$: upright and twice as tall.
Answer: $d_i = -20\ \text{cm}$, $m = +2$
Worked example: Convex mirror
An object is $30\ \text{cm}$ in front of a convex mirror with $f = -15\ \text{cm}$. Find the image distance and magnification.
- $\dfrac{1}{d_i} = -\dfrac{1}{15} - \dfrac{1}{30} = -\dfrac{3}{30}$, so $d_i = -10\ \text{cm}$.
- $m = -\dfrac{-10}{30} = +\dfrac{1}{3}$: virtual, upright and smaller, as always for a convex mirror.
Answer: $d_i = -10\ \text{cm}$, $m = +\frac{1}{3}$