In studying Shankar quantum mechanics p.208 on expressing matrix elements of position operator and momentum operator in terms of the energy basis of the harmonic oscillator Hamiltonian $H=\frac{P^{2}}{2m} + \frac{1}{2} m\omega^{2}X^{2}$ , a question came up to my mind.
Cleary, $H$ eigenbasis $|n\rangle$ can incorporate in its eigenspace only the states that are some superposition of these eigenvectors, that is, physically realizable states residing in the Hilbert space to the physical problem at hand.
But evidently, $X$ basis and $P$ basis have capabilities of spanning vector spaces (as their eigenspaces) with dimensions equal to $R$ whereas $H$ eigenbasis forms a vector space which has dimension equal to $N$. That being said, I think there can be possibilities in which upon applying either position operator $X$ or momentum operator $P$ to one of the energy eigenstate $|n\rangle$, these operators might yield as a resulting state the one that does not belong to $H$ eigenspace. And this at the same time means that $X$ and $P$ operators may not be expressed as some infinite dimensional matrix with its matrix elements written in terms of $H$ basis of the oscillator Hamiltonian.
I think my question here is pretty reasonable, but what am I missing or have mistaken here?