Globally, over the past ten years, computer networks and Internet of Things (IoT) networks have grown significantly due to the increasing amount of data that has been collected, ranging from zettabytes to petabytes. As a result, as the network has expanded, security problems have also emerged. The large data sets involved in these types of attacks can make detection difficult. The developing networks are being used for a multitude of sophisticated purposes, such as smart homes, cities, grids, gadgets, and objects, as well as e-commerce, e-banking, and e-government. As a result of the development of numerous intrusion detection systems (IDS), computer networks are now protected from security and privacy threats. Data confidentiality, integrity, and availability will suffer if IDS prevention efforts fail. Complex attacks can't be handled by traditional methods. There has been a growing interest in advanced deep learning techniques for detecting intrusions and identifying abnormal behavior in networks. This research aims to propose a novel network namely stacked BiLSTM elastic regression classifier (Stack_BiLSTM-ERC) with Aquila optimizer algorithm for feature selection. This optimization method computes use of a cutting-edge transition function that enables it to be transformed into a binary form of the Aquila optimizer. A better solution could be secured once number of possible solutions are found from diverse regions of the search space utilizing the Aquila optimizer method. NSL-KDD and UNSW-NB15 are two datasets that enable learning characteristics from the raw data in order to detect harmful prerequisites characteristics and effective framework patterns. The proposed Stack_BiLSTM-ERC achieves 98.l3% of accuracy, 95.1% of precision, 94.3% of recall and 95.4 of F1-score for NSL-KDD dataset. Moreover, 98.6% of accuracy, 97.2% of precision, 98.5 of recall and 97.5% of F1-score.