Integrating machine learning (ML) into intrusion detection systems (IDS) is considered an important topic for preventing the spread of cyber threats. However, when it comes to machine learning techniques, IDSs face challenges in accurately identifying various types of attacks within the complex structures of a network. This study addresses the lack of research on combining metaheuristic optimization techniques with unsupervised machine learning algorithms in IDS design. The proposed model uses the cuckoo search metaheuristic and the K-means method to improve IDS precision. Here, the cuckoo search algorithm is used to increase the efficiency of feature selection. Meanwhile, the k-means clustering methodology is used to discretize the data and reduce its dimensionality by using two clusters, C1 and C2. The proposed model, developed carefully, includes data preprocessing (handling missing values), data transformation (label encoding), and data normalization. A stochastic operator assesses the impact of the K-means operator. The model is evaluated using an accessible intrusion dataset and compared with other state-of-the-art models. From the research conclusions, the presented model also demonstrates better results compared to the rest, especially when it reaches accuracy (99. 79%), precision (99. 78%), recall (99. 51%), and the F1-score (99).