Step 1: Assume a single ratio variable.
Let the speed of the first train be $r$ times the speed of the second train, so if the second train's speed is $b$, the first train's speed is $a = rb$. We only need to find $r$.
Step 2: Write the lengths in terms of $r$ and $b$.
The length of the first train, using its own crossing time of 25 seconds, is $25a = 25rb$.
The length of the second train, using its own crossing time of 15 seconds, is $15b$.
Step 3: Use the combined crossing condition.
When they cross each other, the combined length divided by the combined speed gives 21 seconds.
\[ \frac{25rb + 15b}{rb + b} = 21 \]
Factor $b$ out of the numerator and denominator, and cancel it since $b \neq 0$.
\[ \frac{25r + 15}{r + 1} = 21 \]
Step 4: Solve for r.
\[ 25r + 15 = 21r + 21 \]
\[ 4r = 6 \]
\[ r = \frac{3}{2} \]
Since $a = rb$, the ratio $a:b$ is the same as $r:1$, which is 3:2.
Final Answer:
The speeds of the two trains are in the ratio 3 : 2.
\[ \boxed{3:2} \]