Heat flows from hot to cold, at a rate proportional to how steeply the temperature changes. Put that together with conservation of energy, and you get the heat equation. Separation of variables and sine and cosine series solve it completely.
Key idea
For a rod $0 < x < L$: $u_t = ku_{xx}$. With ends held at 0 and $u(x, 0) = f(x)$: $$u(x, t) = \sum_{n=1}^{\infty} b_ne^{-k(n\pi/L)^{2}t}\sin\frac{n\pi x}{L},$$ where $b_n$ are the sine coefficients of $f$. With insulated ends ($u_x = 0$ at both ends), use the cosine series instead: $u = \frac{a_0}{2} + \sum a_ne^{-k(n\pi/L)^{2}t}\cos\frac{n\pi x}{L}$, which tends to the average of $f$.
Why it works
The heat flux is $-Ku_x$ (Fourier's law: heat moves down the gradient). In a thin slice $[x, x + \Delta x]$, the heat stored changes at the rate inflow minus outflow, so $c\rho\,u_t\,\Delta x$ $= K u_x(x + \Delta x) - Ku_x(x)$. Divide by $\Delta x$ and let it shrink: $u_t = ku_{xx}$ with $k = \frac{K}{c\rho}$. Each product solution decays at rate $k(n\pi/L)^{2}$, and the series at $t = 0$ must equal $f$, which fixes the $b_n$. High modes (sharp wiggles) die fastest, so the temperature smooths out quickly, and after a while only the first mode matters.
Worked example: Two modes
Solve $u_t = u_{xx}$ on $(0, \pi)$, $u = 0$ at the ends, $u(x, 0) = 3\sin x - \sin 4x$.
- The initial data is already a sine series: $b_1 = 3$, $b_4 = -1$.
- Mode $n$ decays like $e^{-n^{2}t}$.
Answer: $u = 3e^{-t}\sin x - e^{-16t}\sin 4x$
Worked example: A uniform start
A rod $0 < x < \pi$ starts at $u = 1$ and its ends are held at 0 ($k = 1$). Find $u$ and estimate $u\left(\frac{\pi}{2}, 1\right)$.
- Sine series of 1: $b_n = \frac{4}{n\pi}$ for odd $n$, 0 for even $n$.
- $u = \frac{4}{\pi}\sum_{n\ \mathrm{odd}} \frac{1}{n}e^{-n^{2}t}\sin nx$.
- At $t = 1$ the $n = 3$ term has $e^{-9} \approx 0.0001$, so the first term dominates: $\frac{4}{\pi}e^{-1}$.
Answer: $u\left(\frac{\pi}{2}, 1\right) \approx 0.468$
Worked example: Insulated ends
Solve $u_t = u_{xx}$ on $(0, \pi)$ with $u_x = 0$ at both ends and $u(x, 0) = 54 + \cos 3x$.
- Cosine modes: $\cos nx$ decays like $e^{-n^{2}t}$, and the constant mode never decays.
- No heat leaves the rod, so the average temperature 54 is kept.
Answer: $u = 54 + e^{-9t}\cos 3x$, which tends to 54
Ends held at fixed nonzero temperatures $T_1$ and $T_2$? First find the steady state $w(x) = T_1 + (T_2 - T_1)\frac{x}{L}$ (it solves $w'' = 0$). Then $v = u - w$ satisfies the heat equation with zero ends and $v(x, 0) = f - w$, which the series above handles.