Intrusion detection systems (IDS) are essential for the security of IoT systems due to the increased number of potential intruders and attackers resulting from the exponential development of data in today's interconnected world. Machine learning (ML) and deep learning (DL) techniques have emerged as crucial instruments for enhancing the accuracy and efficacy of intrusion detection systems (IDS), allowing them to detect and respond to evolving security threats. In this paper, we propose an ensemble model for intrusion detection based on the NSL-KDD dataset that provides greater accuracy and superior performance metrics than the vast majority of previous works. We compare the proposed model to other traditional ML and DL models, including decision tree, K-nearest neighbor, random forest, logistic regression, and multilayer perceptron models, using a variety of metrics such as Accuracy, MCC, F1 Score, Log Loss, Precision, Recall, and Cohen's Kappa Score. According to the data, the proposed ensemble model (KNN-DT-RF-LR) outperforms other models, with an accuracy of 98.59 percent and the highest scores in other metrics such as MCC and Cohen's Kappa Score. Overall, our proposed ensemble approach is a preferable choice for an intrusion detection system, and by incorporating advanced algorithms and techniques such as K-fold cross-validation, its performance may be enhanced further.