Initially you start with random weights w1, and w. you forward propagate you get the final result Y. You then compare it with the real data and you get an error. After that the error is backpropagate in proportions of the derivative for each weight. If you want to learn more about this mechanism, we explained it more in details in this blog post:

https://medium.com/datathings/vectorized-implementation-of-back-propagation-1011884df84