This study aimed to investigate the associations between hemoglobin (HGB) levels and bone mineral density (BMD) and fracture risk in type 2 diabetes mellitus(T2DM) population of different ages. This cross-sectional study included 641 patients with T2DM (57.9% males). BMD of the femoral neck (FN), total hip (TH), and lumbar spine (LS) were measured using dual-energy X-ray absorptiometry. The 10-year probability of fracture was assessed using a fracture risk assessment tool (FRAX). HGB and other biochemical indices were measured in a certified laboratory at our hospital. Statistical analysis was performed using SPSS 26.0 and R language (R version 4.1.0). Generalized additive models (GAMs) were used to identify the associations between HGB and BMD and fracture risk. Patients with osteoporosis have lower HGB levels than the non-osteoporotic population and lower FN BMD in patients with anemia than in the non-anemic population. In patients with T2DM, there was sex- and age-related variability in the correlation between HGB levels and BMDs and fracture risk. In older men, HGB level was an independent determinant of BMD and was positively correlated with FN and TH BMD. In non-older women, HGB level was an independent determinant of BMD and fracture risk, positively associated with BMDs and negatively associated with 10-year probability of fracture risk. GAMs revealed a positive linear association between HGB level and BMDs in non-older female patients but not in older male patients. Our study provides a new perspective on the association of HGB level and BMDs with fracture risk. Relatively high HGB levels are a protective factor for bone quality in patients with T2DM. However, the bone-protective effect of HGB is influenced by age and sex and persists only in older men and non-older women with T2DM.