Hitesh Sahu
Hitesh SahuHitesh Sahu
  1. Home
  2. ›
  3. posts
  4. ›
  5. …

  6. ›
  7. 2 Forward Propogation

Loading ⏳
Fetching content, this won’t take long…


💡 Did you know?

🍌 Bananas are berries, but strawberries are not.

🍪 This website uses cookies

No personal data is stored on our servers however third party tools Google Analytics cookies to measure traffic and improve your website experience. Learn more

Cover Image for Forward Propagation in Neural Networks

Forward Propagation in Neural Networks

Understand how forward propagation works in neural networks. Learn how inputs move through layers, how weights and biases transform data, and how activation functions generate predictions in deep learning models.

Hitesh Sahu
Written by Hitesh Sahu, a passionate developer and blogger.

Fri Feb 27 2026

Share This on

← Previous

Training a Neural Network

Next →

Vectorized Neural Networks Model Representation

⏩ Forward Propagation (FP)

Forward propagation computes the hypothesis

hΘ(x)h_\Theta(x)hΘ​(x)

by passing the input through each layer of the neural network for each layer.

General Form

For any Network layer lll:

Linear Term: preactivation

z(l)=Θ(l−1)a(l−1)z^{(l)} = \Theta^{(l-1)} a^{(l-1)}z(l)=Θ(l−1)a(l−1)

Activation Term

a(l)=g(z(l))a^{(l)} = g(z^{(l)})a(l)=g(z(l))

Or when look Forward we can rewrite:

z(l+1)=Θ(l)a(l)z^{(l+1)} = \Theta^{(l)} a^{(l)}z(l+1)=Θ(l)a(l) a(l+1)=g(z(l+1))a^{(l+1)} = g\left(z^{(l+1)}\right)a(l+1)=g(z(l+1))

Where

  • a(l)a^{(l)}a(l) = activations of layer lll
  • z(l)z^{(l)}z(l) = linear combination before activation
  • Θ(l)\Theta^{(l)}Θ(l) = weight matrix between layer lll and l+1l+1l+1
  • g(⋅)g(\cdot)g(⋅) = activation function

Advance Example: 4 Layer Neural Network:

Example: Assume a 4-layer neural network.

  • Input layer: 3 units
  • Hidden layer 1: 3 units
  • Hidden layer 2: 3 units
  • Output layer: 1 unit

graph LR

%% Input Layer
    subgraph Input Layer
        x1(((x1)))
        x2(((x2)))
        x3(((x3)))
    end

%% Hidden Layer 1
    subgraph Hidden Layer 1
        a1{a1}
        a2{a2}
        a3{a3}
    end

%% Hidden Layer 2
    subgraph Hidden Layer 2
        b1{b1}
        b2{b2}
        b3{b3}
    end

%% Output Layer
    subgraph Output Layer
        y(((hθx)))
    end

%% Connections: Input → Hidden 1
    x1 --> a1
    x1 --> a2
    x1 --> a3
    x2 --> a1
    x2 --> a2
    x2 --> a3
    x3 --> a1
    x3 --> a2
    x3 --> a3
%% Connections: Hidden 1 → Hidden 2
    a1 --> b1
    a1 --> b2
    a1 --> b3
    a2 --> b1
    a2 --> b2
    a2 --> b3
    a3 --> b1
    a3 --> b2
    a3 --> b3
%% Connections: Hidden 2 → Output
    b1 --> y
    b2 --> y
    b3 --> y

Weight Matrix:

Θ(1)∈R3×4\Theta^{(1)} \in \mathbb{R}^{3 \times 4}Θ(1)∈R3×4 Θ(2)∈R3×4\Theta^{(2)} \in \mathbb{R}^{3 \times 4}Θ(2)∈R3×4 Θ(3)∈R1×4\Theta^{(3)} \in \mathbb{R}^{1 \times 4}Θ(3)∈R1×4

Layer 1 (Input Layer)

Forward Pass

a(1)=xa^{(1)} = xa(1)=x

With bias term:

a(1)=[1x1x2⋮xn]a^{(1)} = \begin{bmatrix} 1 \\ x_1 \\ x_2 \\ \vdots \\ x_n \end{bmatrix}a(1)=​1x1​x2​⋮xn​​​

Layer 2

Linear step:

z(2)=Θ(1)a(1)z^{(2)} = \Theta^{(1)} a^{(1)}z(2)=Θ(1)a(1)

Activation Function:

a(2)=g(z(2))a^{(2)} = g(z^{(2)})a(2)=g(z(2))

Add bias:

a(2)=[1g(z1(2))g(z2(2))⋮]a^{(2)} = \begin{bmatrix} 1 \\ g(z_1^{(2)}) \\ g(z_2^{(2)}) \\ \vdots \end{bmatrix}a(2)=​1g(z1(2)​)g(z2(2)​)⋮​​

Activation of Neurons in Layer 2

First Neuron in layer 2

a1(2)=g(Θ10(1)x0+Θ11(1)x1+Θ12(1)x2+Θ13(1)x3)a^{(2)}_1 = g(\Theta^{(1)}_{10}x_0 + \Theta^{(1)}_{11}x_1 + \Theta^{(1)}_{12}x_2 + \Theta^{(1)}_{13}x_3)a1(2)​=g(Θ10(1)​x0​+Θ11(1)​x1​+Θ12(1)​x2​+Θ13(1)​x3​)

Second Neuron in layer 2

a2(2)=g(Θ20(1)x0+Θ21(1)x1+Θ22(1)x2+Θ23(1)x3)a^{(2)}_2 = g(\Theta^{(1)}_{20}x_0 + \Theta^{(1)}_{21}x_1 + \Theta^{(1)}_{22}x_2 + \Theta^{(1)}_{23}x_3)a2(2)​=g(Θ20(1)​x0​+Θ21(1)​x1​+Θ22(1)​x2​+Θ23(1)​x3​)

Third Neuron in layer 2

a3(2)=g(Θ30(1)x0+Θ31(1)x1+Θ32(1)x2+Θ33(1)x3)a^{(2)}_3 = g(\Theta^{(1)}_{30}x_0 + \Theta^{(1)}_{31}x_1 + \Theta^{(1)}_{32}x_2 + \Theta^{(1)}_{33}x_3)a3(2)​=g(Θ30(1)​x0​+Θ31(1)​x1​+Θ32(1)​x2​+Θ33(1)​x3​)

Generalized

ai(2)=g(Θi0(1)x0+Θi1(1)x1+Θi2(1)x2+Θi3(1)x3)a^{(2)}_i = g(\Theta^{(1)}_{i0}x_0 + \Theta^{(1)}_{i1}x_1 + \Theta^{(1)}_{i2}x_2 + \Theta^{(1)}_{i3}x_3)ai(2)​=g(Θi0(1)​x0​+Θi1(1)​x1​+Θi2(1)​x2​+Θi3(1)​x3​)

for i=1,2,3i = 1,2,3i=1,2,3


Layer 3

Linear step:

z(3)=Θ(2)a(2)z^{(3)} = \Theta^{(2)} a^{(2)}z(3)=Θ(2)a(2)

Activation:

a(3)=g(z(3))a^{(3)} = g(z^{(3)})a(3)=g(z(3))

(Add bias if needed.)

Activation of Neurons in Layer 3

For each neuron iii in layer 3:

ai(3)=g(Θi0(2)a0(2)+Θi1(2)a1(2)+Θi2(2)a2(2)+Θi3(2)a3(2))a^{(3)}_i = g\left( \Theta^{(2)}_{i0}a^{(2)}_0 + \Theta^{(2)}_{i1}a^{(2)}_1 + \Theta^{(2)}_{i2}a^{(2)}_2 + \Theta^{(2)}_{i3}a^{(2)}_3 \right)ai(3)​=g(Θi0(2)​a0(2)​+Θi1(2)​a1(2)​+Θi2(2)​a2(2)​+Θi3(2)​a3(2)​)

for i=1,2,3i = 1,2,3i=1,2,3

hΘ(x)=a(4)h_\Theta(x) = a^{(4)}hΘ​(x)=a(4)

Layer 4 (Output Layer) : Hypothesis

Linear step:

z(4)=Θ(3)a(3)z^{(4)} = \Theta^{(3)} a^{(3)}z(4)=Θ(3)a(3)

Final activation:

a(4)=g(z(4))a^{(4)} = g(z^{(4)})a(4)=g(z(4))

The final hypothesis is First neuron of 3rd layer

hΘ(x)=a1(4)h_\Theta(x) = a^{(4)}_1hΘ​(x)=a1(4)​
AI-DeepLearning/2-Forward-Propogation
Let's work together
+49 176-2019-2523
hiteshkrsahu@gmail.com
WhatsApp
Skype
Munich 🥨, Germany 🇩🇪, EU
Playstore
Hitesh Sahu's apps on Google Play Store
Need Help?
Let's Connect
Navigation
  Home/About
  Skills
  Work/Projects
  Lab/Experiments
  Contribution
  Awards
  Art/Sketches
  Thoughts
  Contact
Links
  Sitemap
  Legal Notice
  Privacy Policy

Made with

NextJS logo

NextJS by

hitesh Sahu

| © 2026 All rights reserved.