A Practical Guide to DNN-Based Intrusion Detection Systems
1. What is Dense Neural Networks (DNNs)
A Practical Guide to DNN-Based Intrusion Detection Systems
1. What is Dense Neural Networks (DNNs)
A Dense Neural Network (DNN) is one of the most widely used deep learning architectures, characterized by its fully connected layers. In such a network, each neuron in one layer is connected to every neuron in the following layer. This structure allows the model to learn complex relationships in the data, making it highly suitable for tasks such as intrusion detection, where traffic features are non-linear and interdependent .
Activation functions are a critical part of dense networks, as they introduce non- linearity that enables the model to capture complex attack patterns. The Rectified Linear Unit (ReLU) is the most commonly used activation, but sigmoid and tanh functions are also employed depending on the classification task .
Dense Neural Networks present several advantages. Theoretically, they are universal approximators, meaning they can model any continuous function given sufficient layers and neurons. This flexibility allows them to handle diverse and complex traffic patterns. Their simplicity also makes them easy to implement and understand, and their versatility allows them to be combined with other layers (such as convolutional or recurrent layers) for hybrid architectures.
However, DNNs also come with limitations. Their large number of parameters makes them prone to overfitting, especially in datasets with limited or imbalanced samples. They are also computationally expensive, since full connectivity requires significant memory and processing power. Moreover, because every feature is treated equally, they can be sensitive to noise or irrelevant attributes, requiring the use of feature selection or regularization techniques to achieve stable results.
The architecture of a DNN is composed of three main parts: the input layer, hidden layers, and the output layer. The input layer receives the raw feature set extracted from the dataset, such as duration, protocol type, or byte count. The hidden layers, which make the model “deep,” progressively transform these inputs through weights and biases that are updated during training. Finally, the output layer produces the prediction, which in the case of IDS corresponds to whether the traffic is normal or belongs to a specific attack class .
Input layer:
The input layer is the first layer of the network. It represents the features or variables of the input data. The number of neurons in this layer is determined by the dimensionality of the input data.
Hidden layers:
Hidden layers are layers between the input and output layers where the network learns to represent patterns in the data. The number of hidden layers and the number of neurons in each layer are important architectural decisions.Deep neural networks have multiple hidden layers, and the term “deep learning” is often used when referring to models with many layers.

DNN Architecture example
Weights and Biases:
Each connection between neurons is associated with a weight, representing the strength of that connection. Additionally, each neuron has an associated bias, contributing to the overall flexibility of the model. During training, the weights and biases are adjusted to minimize the error in the network’s predictions.
Optimizer:
An optimizer is a crucial component in training neural networks. Its primary purpose is to minimize the error or loss function by adjusting the weights of the neural network during the training process. The optimization algorithm defines how the weights are updated based on the computed gradients of the loss with respect to the weights.
The learning rate, a hyperparameter associated with optimizers, is another crucial factor that influences the training process, and tuning it appropriately is essential for achieving good performance.The commonly used optimizers are stochastic Gradient Descent, Adam(Adaptive Moment Estimation),RMsprop(Root Mean Square propagation), Adagrad (Adaptive Gradient Algorithm.)
Output layer:
The output layer of a neural network is the final layer in the architecture and produces the network’s predictions or outputs based on the learned patterns and features from the input data. The structure and characteristics of the output layer depend on the nature of the task the neural network is designed to solve.
2. How Does Our Dense Neural Network Model Work
We proposed a DNN model version of Intrusion Detection system, where we showcase how powerful can a DNN model model mixed with reliable dataset. Where the input would be the Kdd99 dataset , then the input will go through several steps that will be disscued later in the document and that will leads us to a final output of if the the traffic is either malicious (attack 1), or normal traffic (Normal 0) as shown in the figure 10.
We also proposed a multi-class DNN model with same steps as the Binary one the only difference is the out put could be between 5 either normal traffic, Probe , Dos, U2R and R2L all the last four are malicious traffic attack.

Our DNN model
2.1 Preprocessing of KDD Cup 99 Dataset
Before training our Deep Neural Network (DNN) models, it was necessary to carefully preprocess the KDD Cup 99 dataset. Raw network traffic records contain both categorical and numerical attributes, as well as imbalanced classes, which
makes them unsuitable for direct input into a deep learning model. The preprocessing pipeline consisted of the following key steps:
Handling Categorical Features
Several attributes in the dataset, such as protocol_type, service, and flag, are categorical. Since deep learning models require numerical input, these fields were transformed into numeric representations. Two encoding strategies were considered:
One-Hot Encoding: Converts each category into a binary vector (e.g., TCP
→ [1,0,0], UDP → [0,1,0], ICMP → [0,0,1]). This prevents false ordinal relationships but significantly increases dimensionality.
Label Encoding: Assigns each category a unique integer (e.g., TCP → 0, UDP → 1, ICMP → 2). This is memory-efficient but may introduce unintended ordinal bias.
In practice, a hybrid strategy was applied: one-hot encoding for low-cardinality features, and label encoding for high-cardinality attributes, ensuring both interpretability and efficiency.

This selected 3 Categorical features because they contain non-numerical that cannot be directly processed by DNN model.

Each feature is categorical feature is converted into binary 0 or 1.
Scaling of Numerical Features
Attributes such as src_bytes, dst_bytes, and duration vary significantly in scale. To prevent features with large ranges from dominating the training process, normalization was applied using StandardScaler, which rescales values to have zero mean and unit variance [Equation 2]. This normalization improved convergence and stability during training.
Handling Missing and Invalid Values
To ensure model robustness, missing or invalid values were checked in both training and testing sets. Any NaN or infinite values were replaced with zero. This step eliminated inconsistencies that could otherwise cause runtime errors or degrade performance.
Binary and Multi-Class Label Encoding
Since the project required evaluation in both binary (Normal vs. Attack) and multi- class (DoS, Probe, R2L, U2R, Normal) settings, two different label encodings were applied:
Binary Classification: All attack types were grouped under a single label (“1”), while normal traffic was labeled as (“0”).
Multi-Class Classification: Each attack was assigned to one of the four major categories defined in the dataset (DoS, Probe, R2L, U2R). This allowed the model to differentiate between attack strategies instead of treating all anomalies as a single group.
This comprehensive preprocessing ensures that the data is properly structured for both classification scenarios while maintaining the integrity of important features identified in the feature importance analysis. The “other” category in multi-class encoding provides robustness to handle previously unseen attack types during testing.
2.2 Models Evaluation
- Binary DNN
The next step is to create the DNN model for both binary and multi-class:
For binary classification (normal vs. attack), a sequential model was constructed comprising three hidden layers with 128, 64, and 32 neurons respectively, using ReLU activation functions and incorporating batch normalization with 30% dropout after each layer for regularization, culminating in a single sigmoid output neuron optimized with binary cross-entropy loss. The only difference between binary and the multiclass is the output of 5 (normal, probe, R2L, U2R, DoS).
Now since both models are defined what would be next is to train both models and feed them the preprocessed dataset from before which gave us the following results:
For both models the results consist of evaluation matrix and classification report (Accuracy, Recall, Precision and f1-score).
Classification Report

The classification results, shown in Table 4, highlight the power and strength of the proposed intrusion detection system. The Binary Dense neural network model demonstrated exemplary performance reaching 98% accuracy and 98% F1-score across both classes. As for attack class there was a marginal disparity between precision and recall indicating a deliberate trade off in favoring specificity over sensitivity. These finding not only validate the feature selection methodology but establish the impact of the correct dataset choice with the right DL model.
- Multi-Class DNN

As For the multi-class classification report the results highlight the strength and robustness performance of the DNN model on the KDD Cup 99 dataset, reaching an overall of 96.3% accuracy. This result suggests varying degrees of feature separability between normal traffic and different attack categories. The model also established a strong and balanced precision and recall for each class confirming the DNN’s capability.
The DNN approach proved to be very efficient with less misclassification for Intrusion Detection System. With the Binary model achieving a 98% accuracy and the multi-class doesn’t fall behind by much achieving 96% accuracy. Making both models very strong and robust.
메타데이터
- post_id
- 6cfdff715075
- slug
- a-practical-guide-to-dnn-based-intrusion-detection-systems-6cfdff715075
- url
- https://medium.com/@elkadiayoub785/a-practical-guide-to-dnn-based-intrusion-detection-systems-6cfdff715075
- canonical_url
- https://medium.com/@elkadiayoub785/a-practical-guide-to-dnn-based-intrusion-detection-systems-6cfdff715075
- author_url
- https://medium.com/@elkadiayoub785
- status
- ok
- fetched_at
- 2026-07-20 09:16:42