Objective To analyze the influence of HIV in penitentiary institutions through an exhaustive lexiconmetric and sentiment analysis of news in the Spanish written press related to HIV and prison. Material an method observational, descriptive, and retrospective design based on news published in Spanish newspapers from 1981 to 2020, linking HIV infection with penitentiary institutions. Natural language processing and lexiconmetry techniques were used, using the Python programming language and ATLAS Ti v.9 software. Result: 318 articles were analyzed, with 10,502 distinct words. The sentiment of news was evaluated in three different periods: the discovery of HIV, and the periods before and after the existence of antiretroviral treatments. N-gram analysis and word cloud creation were carried out for each period. In the initial phase, ignorance predominated, and prominent terms such as "homosexual," "isolate," "test," "trial," or "confirm" were observed. In the period before antiretroviral treatments, news reflected negative feelings and criticism of prison policy, with keywords such as "give birth," "drug," "carrier," or "disease." With the arrival of treatments, news showed an evolution towards a more positive tone, highlighting terms such as "treatment," "release," or "syringes”.Conclusions: The presence of HIV in Spanish prisons has experienced a significant evolution from an alarming situation to an improvement in the care of inmates, driven by institutional adaptation and advances in antiretroviral treatments.