Machine learning is an emerging area in research. Nowadays, researchers are utilizing machine learning across all domains to find optimal solutions. Machine learning facilitates the growth of an intrusion detection system (IDS) in the context of cyber security. These systems are proposed to identify and classify cyber-attacks on the network. However, an exhaustive assessment and performance evolution of various machine learning algorithms remains unavailable. In this study, we introduce a framework designed to nurture a versatile and efficient IDS adept at identifying and categorizing unexpected and evolving cyber threats. This is achieved through the use of Recursive Feature Elimination (RFE). In RFE, the algorithm is run recursively until a selected number of features are identified to enhance efficiency and reduce computational cost. The rapid detection of these attacks can facilitate the identification of potential intruders, and the damage will be lowered. We attained remarkable accuracies, with an average rate between 98% and 99% across all the classifiers and against all four types of attacks. The random forest and decision tree models stood out, each achieving peak accuracies of 99% in both KDD-99 and NSL-KDD Datasets.