In this paper, we show that the problem of determining if the identity matrix belongs to a finitely generated semigroup of 2 × 2 matrices from the modular group PSL 2 (Z) and thus the Special Linear group SL 2 (Z) is solvable in NP. From this fact, we can immediately derive that the fundamental problem of whether a given finite set of matrices from SL 2 (Z) or PSL 2 (Z) generates a group or free semigroup is also decidable in NP. The previous algorithm for these problems, shown in 2005 by Choffrut and Karhumäki, was in EXPSPACE mainly due to the translation of matrices into exponentially long words over a binary alphabet {s, r} and further constructions with a large nondeterministic finite state automaton that is built on these words. Our algorithm is based on various new techniques that allow us to operate with compressed word representations of matrices without explicit expansions. When combined with the known NP-hard lower bound, this proves that the membership problem for the identity problem, the group problem and the freeness problem in SL 2 (Z) are NP-complete.