This study focuses on improving the detection of breast cancer at an early stage. The standard approach for diagnosing breast cancer is mammography, but it is pretty tedious as it is subject to subjective analysis. The study will examine how deep learning-based techniques are used in mammography analysis to improve the screening process in order to overcome these obstacles. Various computer vision models, including Visual Geometry Group (VGG) 19, inceptionV3, and custom 20 Convolutional Neural Network (CNN) architecture, are investigated using the Digital Database for Screening Mammography (DDSM) mammogram dataset. The DDSM is widely used for mammographic image analysis in the research community. In the domain of CNNs, the models have demonstrated considerable promise due to their efficacy in various tasks, such as image recog- nition and classification. It is also seen that the CNN model’s performance is enhanced using hyperparameter optimization. However, manually tuning hyper- parameters is laborious and time-consuming. To overcome this challenge, CNN’s automatic hyperparameter optimization uses metaheuristic approaches based on the population. This automation mitigates the time required for finding optimal hyperparameters and boosts the CNN model’s efficacy. The proposed approach uses the Bacterial Foraging Optimization (BFO) algorithm to optimize CNN to enhance breast cancer detection. BFO is utilized to optimize various hyperparam- eters, such as filter size, number of filters, and hidden layers in the CNN model. It is demonstrated through experiments that the proposed BFO-CNN method achieves better performance than other state-of-the-art methods by 7.62% for the VGG 19, by 9.16% for the inceptionV3, and by 1.78% for the custom CNN- 20 layers. In conclusion, this work aims to leverage deep learning techniques and automatic hyperparameter optimization to enhance breast cancer detec- tion through mammogram analysis. The BFO-CNN model has much potential to improve breast cancer diagnosis accuracy compared to conventional CNN architecture.