NSAIDs work by inhibiting the activity of cyclooxygenase (COX) enzymes, specifically COX-1 and COX-2. These enzymes play a crucial role in the biosynthesis of prostaglandins, which are lipid compounds that contribute to inflammation, pain, and fever. By blocking COX enzymes, NSAIDs effectively reduce the production of prostaglandins, thereby alleviating symptoms.