5. On a straight line, three points $A$, $B$, and $C$ are arranged in sequence, and $A B=6, A C=24, D$ is a point outside the line, and $D A$ $\perp A B$. When $\angle B D C$ takes the maximum value, $A D=$ $\qquad$ .
5. 12 .

Let $\angle B D C=\theta\left(\theta<90^{\circ}\right), \triangle B C D$'s circumcircle $\odot O$ has a radius of $R$. Then $\sin \theta=\frac{B C}{2 R}$.
When $R$ decreases, $\theta$ increases.
Therefore, when $\odot O$ is tangent to $A D$ at point $D$, $\theta$ is maximized.
At this time, $A D^{2}=A B \cdot A C=12^{2} \Rightarrow A D=12$.