Bariatric surgery, a significant intervention for obesity, may influence weight loss through changes in gut microbiota, particularly the Firmicutes and Bacteroidetes. This study explores these potential shifts and their metabolic implications. We conducted a cross-sectional study involving patients who had undergone bariatric surgery. Stool samples were collected at baseline, 3 months, and 6 months post-operation. We performed DNA extraction and quantified the bacterial phyla Firmicutes and Bacteroidetes to assess changes in the gut microbiota over time. Our research revealed a significant alteration in the gut microbiota following bariatric surgery. In diabetic individuals, there was a marked increase in the average number of Firmicutes bacteria at both 3 and 6 months post-operation, compared to pre-surgery levels. In contrast, non-diabetic subjects experienced a notable decrease in Firmicutes during the same timeframe. Regarding Bacteroidetes bacteria, the trend was reversed; diabetic patients showed a significant reduction, while non-diabetics exhibited an increase after the surgery. These findings highlight the dynamic changes in gut microbiota composition associated with bariatric surgery and its potential link to metabolic changes post-operation. These findings suggest that obesity alters the gut's microbial composition. The observed bacterial fluctuations, particularly in the dominant Firmicutes and Bacteroidetes groups, are likely contributors to the weight loss experienced post-surgery. This alteration in gut bacteria underscores the complex interplay between microbiota and metabolic health, highlighting potential avenues for therapeutic intervention.