We would like to find the order of $x \bmod{n}$. Shor --- on page 318 of his 1999 paper --- instructs:
First, we find $q$, the power of 2 with $n^2 \leq q < 2n^2$. [...] Next, we put the first register in the uniform superposition of states representing numbers $a$ (mod $q$). This leaves our machine in the state
$$\frac{1}{q^{1/2}} \sum_{a=0}^{q - 1} |a\rangle |x^a \bmod{n}\rangle$$
What's the maximum length of this state? It must be at most $2n^2$ because that is at most $q$ --- by construction. But I can't see this.
How large can $a$ be? It can be as large as $n - 1$ because no element $x$ can have order greater than $n - 1$. So $|a\rangle$ takes as many q-bits as $n$ --- say $m$ q-bits. How many q-bits do we need for $|x^a \bmod{n}\rangle$? It cannot take more than $m$ q-bits. Hence, the state above cannot take more than $2m$ q-bits. So why is $n^2$ even involved here? What am I missing?