Internet of Things (IoT) is an intelligent network which links smart objects to the Internet. A great amount of IoT devices are linking to the Internet, so far a lot of of these devices are apprehensive, exposing them to a number of security threats. Most IoT devices are resource constrained hence making it difficult to secure them using existing security techniques. Numerous researchers have developed intrusion detection model implemented at IoT gateways. In this work, to defend cyberspace a novel detection technique with a novel concept was introduced which helps the deep learning model. Here, the process includes two stages such as classification as well as feature extraction. Initially, the feature extraction is performed, from the subjected input data the extraction of features is carried out with the aid of the well-known Principal Component Analysis (PCA). Then, the extracted features are fed to the classification stage; here the Convolutional Neural network (CNN) model is exploited. The presence of attacks is classified by the classifiers, the attacks such as R2L, denial of service (DoS), U2R as well as a probe. For this, a novel optimization approach is called Hybrid Whale Optimization Algorithm (WOA)-Bat Algorithm (BA). This optimization is mainly exploited to choose optimally the hidden neurons. The developed algorithm performance is analyzed with the existing techniques regarding both the positive as well as negative metrics, and the analysis revealed the superiority of the proposed model.