With the rapid development of Internet technology, network attacks occur frequently and numerous hidden dangers appear in network security. Therefore, improving the performance of intrusion detection systems to detect and defend against attacks is the key to ensuring network security. However, in the face of complex and massive network data feature information, traditional machine learning methods suffer from data imbalance and feature redundancy, which results in low detection rates, high false alarm rates and poor real-time performance of intrusion detection systems. Therefore, to address these problems, this paper proposes a data imbalance-based Convolutional Neural Network Intrusion Detection Method (CNN-IDMDI). First, an oversampling method is used to solve the data imbalance problem by decomposing the increased number of samples for the few attacks with multiple sampling to form multiple sub-samples. Second, the gradient coordination mechanism and the improved loss function Focal Loss are combined to calculate the loss between the actual and expected values to detect network malicious attacks in high-dimensional and unbalanced data. Finally, the methods in this paper are compared with the current mainstream intrusion detection methods on the NSL-KDD dataset for binary and multi-classification detection. The experimental results show that the method in this paper can effectively improve the effectiveness of CNN intrusion detection and network anomaly. The average accuracy of the CNN intrusion detection method based on data imbalance for binary intrusion detection is 98.73% and the implementation time of the method is 1.42 s, which is 15.45%, 12.76%, and 2.91% higher than the average accuracy of the CNN, the CNN Long Short-Term Memory (CNN-LSTM) and the CNN Neural-induced Support Vector Machine (CNN-NSVM) methods, respectively, and the detection time is saved by 0.82 s, 0.72 s, and 0.61 s, respectively. The average accuracy of the CNN intrusion detection method based on data imbalance for multi-classification intrusion detection is 94.55% and the time required to complete the detection is 2.96 s. This improves the average accuracy by 16.09%, 12.71%, and 3.66% compared with the CNN, CNN-LSTM and CNN-NSVM methods, respectively. It is also quicker, as the time consumption of CNN is 8.84 s, CNN-LSTM is 8.31 s and CNN-NSVM is 6.43 s. Therefore, the CNN-IDMDI method for intrusion detection proposed in this paper has higher accuracy and faster speed.