  Lomonaco and Kauffman developed a knot mosaic system to introduce a precise and workable definition of a quantum knot system. This definition is intended to represent an actual physical quantum system. A knot (m,n)-mosaic is an $m \times n$ matrix of mosaic tiles ($T_0$ through $T_{10}$ depicted in the introduction) representing a knot or a link by adjoining properly that is called suitably connected. $D^{(m,n)}$ is the total number of all knot (m,n)-mosaics. This value indicates the dimension of the Hilbert space of these quantum knot system. $D^{(m,n)}$ is already found for $m,n \leq 6$ by the authors.   In this paper, we construct an algorithm producing the precise value of $D^{(m,n)}$ for $m,n \geq 2$ that uses recurrence relations of state matrices that turn out to be remarkably efficient to count knot mosaics. $$ D^{(m,n)} = 2 \, \| (X_{m-2}+O_{m-2})^{n-2} \| $$ where $2^{m-2} \times 2^{m-2}$ matrices $X_{m-2}$ and $O_{m-2}$ are defined by $$ X_{k+1} = \begin{bmatrix} X_k & O_k \\ O_k & X_k \end{bmatrix} \ \mbox{and } \ O_{k+1} = \begin{bmatrix} O_k & X_k \\ X_k & 4 \, O_k \end{bmatrix} $$ for $k=0,1, \cdots, m-3$, with $1 \times 1$ matrices $X_0 = \begin{bmatrix} 1 \end{bmatrix}$ and $O_0 = \begin{bmatrix} 1 \end{bmatrix}$. Here $\|N\|$ denotes the sum of all entries of a matrix $N$. For $n=2$, $(X_{m-2}+O_{m-2})^0$ means the identity matrix of size $2^{m-2} \times 2^{m-2}$. 
Quantum knots and the number of knot mosaics