The aim of this study was to analyse the effect of intramammary infection (IMI) on N-acetyl-β-D-glucosaminidase (NAGase) enzyme values and to study its predictive capacity using different algorithms. To do this, 26 sheep free of intramammary infection were selected, and their somatic cell count (SCC), NAGase and bacteriological culture were monitored for 2 weeks. They were then subjected to a series of unhealthy situations (UHS) for the mammary gland, and these variables were monitored for a further 4 weeks. IMI was established in 12 of the 26 sheep. In the 4 days following infection, a very marked increase in enzyme values was observed in the infected glands. The algorithm that obtained the best result was the one that detected, in at least two of the first four days after infection, an increase in NAGase values greater than 30% compared to the average of the 3 days prior to infection, obtaining an area under the curve (AUC) of 0.90, an accuracy of 89.8%, a sensitivity of 95.2% and a specificity of 85.7%.