Cortisol is a key glucocorticoid hormone involved in the physiological stress response of animals. Its secretion, largely regulated by the hypothalamic-pituitary-adrenal (HPA) axis, is essential for animal welfare and growth. Recent studies have shown that this stress-regulatory system operates in coordination with the gut microbiota, communicating with the brain through the gut-brain axis. Given that the diet can modulate microbial composition, dietary interventions thus offer potential in modulating HPA activity. Inulin is a prebiotic that promotes beneficial gut microbiota such as Lactobacilli and enhances intestinal health. Microbial fermentation exerts anti-inflammatory effects and strengthens the gut barrier through short-chain fatty acids, potentially influencing stress physiology via the gut-brain axis. In this study, we focused on the effects of inulin on cortisol in saliva and hair samples of pigs as indicators of acute and chronic stress responses, respectively. Animals were housed at low or high density and received inulin supplementation or none. Mixing at weaning and at the start of fattening was used as an acute social stressor. Saliva samples were collected from 3 pens per experimental group, from 84 animals before and after animal mixing. Due to contamination, only 153 samples were retained for analysis. Hair samples were collected from 48 animals at the end of the post-weaning phase and 5 weeks into the fattening phase. Due to insufficient hair material, only 53 samples were suitable for analysis. Cortisol quantification was done by ELISA. Data were analysed using a Four Parameter Logistic (4PL) calibration curve, and linear mixed-effects models (LLMs) were performed on the obtained results to verify significance. Inulin reduced basal salivary cortisol levels before the second animal mixing (P < 0.05) but pre- and post-mixing cortisol levels did not differ significantly at either phase, nor did cortisol elevation differ between groups. For chronic stress, a significant interaction between animal density and diet was observed at the end of the post-weaning period (P < 0.05), where inulin mitigated the effect of high density. Overall, environmental and dietary factors jointly influenced stress responses. To conclude, beyond its well-established benefits for intestinal health, inulin may serve as a promising dietary strategy to enhance animal welfare by modulating circulating cortisol levels and mitigating stress responses in pigs.