To evaluate the impact of the CD4 count on ESAT6-CFP10 (EC) skin test, QuantiFERON-TB Gold In-tube test (QFT) and tuberculin skin test (TST) in a large prison and communities in Jiangsu Province among people living with HIV (PLHIV). Participants in communities were tested with the QFT and EC skin test and in prison were tested with the QFT, TST and EC skin test. A 4-knotted restricted cubic spline fitted for Logistic models was used to explore the cutoff point of CD4 count and the associations between changes in CD4 count and Mycobacterium tuberculosis (M.tb) infection. Among 1,815 PLHIV included, 19.3% (350) were from prisons and 80.7% (1465) were identified through community screenings. M.tb infection rates were 12.2% and 8.3% through QFT and EC tests, respectively. Odd Ratios (ORs) for infection increased with CD4 counts, peaking at 618 cells/mm3 for EC, 392 cells/mm3 for QFT, then plateaued. However, the pattern differed for EC between prison and screening scenarios. In prison settings, M.tb infection increased with CD4 count from 0 to 350 cells/mm3, plateaued until 500 cells/mm3, and then persistently increased. Conversely, for community, ORs decreased until 300 cells/mm3, followed by an increase between 300 and 729 cells/mm3, after which they continued to rise persistently. Our cross-sectional study among PLHIV revealed a higher rate of M.tb infection in prison compared to the community. The relationship between CD4 count and infection became negative after a certain threshold. This pivotal point differed with detection methods, with QFT showing lower CD4 thresholds than EC.