What is a neural network, and how does it learn from data?

Updated Feb 20, 2026

Short answer

A neural network is a machine learning model inspired by the brain that learns patterns by adjusting connections between artificial neurons. It takes input data, makes predictions, measures errors, and repeatedly updates its internal parameters to improve performance.

Deep explanation

A neural network learns by finding a mathematical relationship between inputs and outputs. Instead of being explicitly programmed with rules, it discovers useful patterns from examples.

A typical neural network contains:

  • Input layer: Receives raw features such as pixels, words, or sensor values.
  • Hidden layers: Transform inputs through learned mathematical operations.
  • Output layer: Produces a prediction, such as a class label or a probability.

Each connection between neurons has a weight, which represents how strongly one signal influences another. Neurons also usually have a bias, which helps shift the final calculation.

A simplified neuron works like this:

neuron.py
output = activation(weight1 * input1 + weight2 * input2 + bias)

The activation function allows the network to learn complex, non-linear patterns instead of only simple relationships.

The learning process

Training a neural network usually happens through a cycle:

Rendering diagram…
  1. Forward pass The network receives an example and calculates a prediction.
  1. Loss calculation The prediction is compared with the correct answer using a loss function. The loss represents how wrong the model was.
  1. Backpropagation The network calculates how much each weight contributed to the error. It uses calculus, specifically gradients, to determine the direction of improvement.
  1. Weight update An optimization algorithm such as gradient descent changes the weights slightly to reduce future errors.

A neural network does not memorize answers; it learns parameter values that help it generalize to new examples.

Why repeated training works

A single update usually makes only a tiny improvement. Training involves thousands or millions of examples because the network gradually discovers better internal representations.

For example, an image recognition network might first learn simple patterns:

  • Early layers detect edges and colors.
  • Middle layers detect shapes and textures.
  • Later layers combine these features to recognize objects.

This layered feature learning is one reason deep neural networks are powerful.

Important trade-offs

ChoiceBenefitTrade-off
More layersLearns more complex patternsRequires more data and computation
More parametersHigher learning capacityHigher risk of overfitting
More trainingBetter optimizationTakes more time and resources

The goal of training is not to make the model perfect on training data; it is to make it perform well on unseen data.

A common challenge is overfitting, where a model learns the training examples too closely but fails on new inputs. Techniques such as regularization, dropout, data augmentation, and collecting more training data help improve generalization.

A useful interview rule: training is the process of adjusting weights; inference is the process of using those learned weights to make predictions.

Neural networks are especially effective when there are large amounts of data and complex patterns, such as images, speech, language, and recommendation systems. However, they often require significant computational resources and may be harder to interpret than simpler models.

Real-world example

Consider an email spam detector. The network receives thousands of labeled emails marked as either "spam" or "not spam." It converts email information into numerical features, such as word patterns and message structure, then learns which combinations are associated with spam.

During training, the model predicts whether an email is spam, compares its prediction with the correct label, and adjusts its weights. After enough examples, it can identify patterns in new emails it has never seen before.

spam_model.py
prediction = model.predict(email_features)
if prediction > 0.5:
print("Spam")
else:
print("Not spam")

The model improves because each mistake becomes feedback that guides future weight updates.

Common mistakes

  • * **Brain comparison** - Assuming neural networks think like humans. They are mathematical systems that learn statistical patterns, not conscious reasoning engines.
  • * **Data misconception** - Believing more data always guarantees success. Poor-quality or biased data can produce poor predictions.
  • * **Training confusion** - Mixing up training and inference. Training changes weights
  • inference only uses the learned model.
  • * **Overfitting** - Celebrating high training accuracy while ignoring performance on new data. Always evaluate with unseen validation or test data.
  • * **Magic algorithm** - Thinking neural networks automatically solve every problem. They still require good data, suitable architecture, and careful evaluation.

Follow-up questions

  • What is the difference between a neural network and a traditional machine learning model?
  • What is backpropagation in a neural network?
  • Why do neural networks need activation functions?
  • What causes overfitting in neural networks?
  • What is the difference between training and inference?

More Neural Networks interview questions

View all →