The Internet of Things (IoT) represents a transformative paradigm in which objects and devices interconnect, with 5G technology accelerating its expansion as the primary infrastructure for ubiquitous connectivity. This proliferation of IoT within our lives introduces significant security and privacy challenges. The interconnection of every smart object in urban settings amplifies the susceptibility to diverse security threats, potentially rendering IoT-based smart cities insecure. Ensuring the security and resilience of these digital urban environments is imperative, particularly as cities become increasingly computerized and densely populated with interconnected devices. Detecting and mitigating potential computer security attacks is of paramount importance in safeguarding the integrity and functionality of smart cities. In this research, we present an intrusion detection model derived from data extracted through simulating the SYNFLOOD attack scenario, a prominent form of Denial of Service (DoS) attack in the realm of IoT security. The suggested detection model classifies, trained and validated the imported data using the k-folds method, and creates a unique detection model. The proposed model is fast and effectively enables all IoT networks to communicate information without compromising privacy. It enhances the detection process by employing data pre-processing and balancing. In this work, the experiments’ accuracy are stable which proves the success of the model for the six used machine learning algorithms resulted in a very good performance with an accuracy of 92.3% for the Decision Tree and Neural Network.