NSL‑KDD Dataset — Expanded Overview

Fall 2025 Datathon • Intrusion Detection

What is NSL‑KDD?

NSL‑KDD is a curated revision of the KDD’99 intrusion‑detection dataset created by the Canadian Institute for Cybersecurity (UNB). It removes duplicated records and balances example difficulty so that machine‑learning algorithms can be compared more fairly.

Why it matters: KDD’99’s heavy duplication and imbalance could inflate accuracy. NSL‑KDD addresses these issues, making it suitable for pedagogy and benchmarking.

Labeling: How to tell attacks from normal traffic

Each row (connection record) includes a label column at the end. If the label equals normal. the record is benign; any other string denotes a specific attack (e.g., neptune., smurf., nmap., guess_passwd.).

Label value (string)Meaning
normal.Benign (non‑attack) connection
neptune., smurf., teardrop., back., land.DoS attacks
portsweep., ipsweep., nmap., satan.Probe attacks
guess_passwd., ftp_write., imap., phf.R2L attacks
buffer_overflow., loadmodule., rootkit., perl.U2R attacks

Binary target convenience column

You can convert the string label to a binary flag (0=normal, 1=attack) like this:

import pandas as pd

cols = [f"f{i}" for i in range(1, 42)] + ["label"]  # 41 features + label
df = pd.read_csv("KDDTrain+.txt", header=None, names=cols)
df["attack_flag"] = (df["label"] != "normal.").astype(int)
print(df["label"].value_counts().head())
print(df["attack_flag"].value_counts())

Key Files

FileDescriptionRecords
KDDTrain+.txtFull training set125,973
KDDTest+.txtFull test set22,544
KDDTrain+_20Percent.txt20% train subset25,192
KDDTest-21.txtTest subset (excludes easiest)11,850
.arff variantsWEKA-ready versions—

Feature Schema (41 inputs)

Grouped as:

  • Basic (1–9): duration, protocol_type, service, flag, src_bytes, dst_bytes, …
  • Content‑based (10–22): hot, num_failed_logins, root_shell, num_file_creations, …
  • Time‑based traffic (23–31): count, srv_count, same_srv_rate, …
  • Host‑based traffic (32–41): dst_host_count, dst_host_srv_count, dst_host_srv_serror_rate, …

Three features are categorical: protocol_type, service, flag.

Attack Taxonomy

  • DoS: neptune, smurf, teardrop, back, land
  • Probe: portsweep, ipsweep, nmap, satan
  • R2L: guess_passwd, ftp_write, imap, phf
  • U2R: buffer_overflow, loadmodule, rootkit, perl

Use either binary (attack vs normal) or multi‑class (specific attack) targets.

Common Pre‑processing

  1. Split: Train on KDDTrain+.txt, test on KDDTest+.txt (or KDDTest‑21.txt).
  2. Encode categoricals: One‑hot protocol_type, service, flag.
  3. Scale numerics: Standardize/normalize as appropriate.
  4. Imbalance: Stratified splits, class weights, or balanced sampling.
  5. Metrics: Report precision/recall/F1 (macro), ROC‑AUC/PR‑AUC; highlight U2R and R2L.

Limitations

References

No. Feature Name Description Type Category
1durationLength of the connection in seconds.ContinuousBasic
2protocol_typeType of the protocol (e.g., tcp, udp, icmp).CategoricalBasic
3serviceNetwork service on the destination (e.g., http, smtp, ftp, private).CategoricalBasic
4flagStatus of the connection (e.g., SF, REJ, S0).CategoricalBasic
5src_bytesNumber of data bytes from source to destination.ContinuousBasic
6dst_bytesNumber of data bytes from destination to source.ContinuousBasic
7land1 if connection is from/to the same host/port; 0 otherwise.BinaryBasic
8wrong_fragmentNumber of 'wrong' fragments.ContinuousBasic
9urgentNumber of urgent packets.ContinuousBasic
10hotNumber of 'hot' indicators (e.g., successful login attempts).ContinuousContent
11num_failed_loginsNumber of failed login attempts.ContinuousContent
12logged_in1 if successfully logged in; 0 otherwise.BinaryContent
13num_compromisedNumber of 'compromised' conditions.ContinuousContent
14root_shell1 if root shell is obtained; 0 otherwise.BinaryContent
15su_attempted1 if 'su root' command was attempted; 0 otherwise.BinaryContent
16num_rootNumber of root accesses.ContinuousContent
17num_file_creationsNumber of file creation operations.ContinuousContent
18num_shellsNumber of shell prompts.ContinuousContent
19num_access_filesNumber of operations on access control files.ContinuousContent
20num_outbound_cmdsNumber of outbound commands in an ftp session.BinaryContent
21is_host_login1 if the connection is a host login; 0 otherwise.BinaryContent
22is_guest_login1 if the login is a guest login; 0 otherwise.BinaryContent
23countNumber of connections to the same destination host as the current connection in the last two seconds.ContinuousTime-based
24srv_countNumber of connections to the same service as the current connection in the last two seconds.ContinuousTime-based
25serror_rate% of connections in count that had SYN errors.ContinuousTime-based
26srv_serror_rate% of connections in srv_count that had SYN errors.ContinuousTime-based
27rerror_rate% of connections in count that had REJ errors (connection rejected).ContinuousTime-based
28srv_rerror_rate% of connections in srv_count that had REJ errors.ContinuousTime-based
29same_srv_rate% of connections in count that were to the same service.ContinuousTime-based
30diff_srv_rate% of connections in count that were to different services.ContinuousTime-based
31srv_diff_host_rate% of connections in srv_count that were to different destination hosts.ContinuousTime-based
32dst_host_countNumber of connections with the same destination host (last 100 connections).ContinuousHost-based
33dst_host_srv_countNumber of connections with same service and same destination host.ContinuousHost-based
34dst_host_same_srv_rate% of connections in dst_host_count that were to the same service.ContinuousHost-based
35dst_host_diff_srv_rate% of connections in dst_host_count that were to different services.ContinuousHost-based
36dst_host_same_src_port_rate% of connections in dst_host_count that were from the same source port.ContinuousHost-based
37dst_host_srv_diff_host_rate% of connections in dst_host_srv_count that were to different destination hosts.ContinuousHost-based
38dst_host_serror_rate% of connections in dst_host_count that had SYN errors.ContinuousHost-based
39dst_host_srv_serror_rate% of connections in dst_host_srv_count that had SYN errors.ContinuousHost-based
40dst_host_rerror_rate% of connections in dst_host_count that had REJ errors.ContinuousHost-based
41dst_host_srv_rerror_rate% of connections in dst_host_srv_count that had REJ errors.ContinuousHost-based
42attack_typeThe class label: normal or specific attack category/type (e.g., neptune, smurf).CategoricalTarget
43difficulty_levelDifficulty score of the test record (1–21).DiscreteTarget

Link to the dataset

https://raw.githubusercontent.com/defcom17/NSL_KDD/master/KDDTest+.txt