Back propagation through a simple convolutional neural network
The backpropagation algorithm attributes a penalty per weight in the network. To get the associated gradient for each weight we need to backpropagate the error back to its layer using the derivative chain rule.
Flattening layer
The derivative of a layer depends on the function that is being applied. In the case of the flattening layer it is simply reshaping (a mapping) the values. Thus no additional loss will be added at this layer. All you need to know is how the flattening occurs.
For example if the forward pass flattening is
$flatten\begin{pmatrix}
  a &amp; b\\ 
  c &amp; d
\end{pmatrix} = \begin{pmatrix}
  a \\
  b \\
  c \\  
  d
\end{pmatrix}$,
then you can easily map the associated cost so far back to the $2 \times 2 \times 1$ feature map.
Max pooling layer
In the forward pass the max pooling layer is taking the maximum value in a $3 \times 3$ window that is passed along your image. For example the bold values in the first $3 \times 3$ window would have a maximum of $11$.
$maxpooling \begin{pmatrix}
  \bf{1} &amp; \bf{2} &amp; \bf{3} &amp; 4 \\ 
  \bf{5} &amp; \bf{6} &amp; \bf{7} &amp; 8 \\
  \bf{9} &amp; \bf{10} &amp; \bf{11} &amp; 12 \\
  13 &amp; 14 &amp; 15 &amp; 16
\end{pmatrix} = \begin{pmatrix}
  \bf{11} &amp; 12\\ 
  15 &amp; 16
\end{pmatrix}$
Thus the resulting error backpropagation would only pass through the maximum values which were passed down by the forward pass. For all other values the error term would not backpropagate. Thus the current error matrix you had backpropagating until this point would be multiplied by
$\begin{pmatrix}
  0 &amp; 0 &amp; 0 &amp; 0 \\ 
  0 &amp; 0 &amp; 0 &amp; 0 \\
  0 &amp; 0 &amp; 1 &amp; 1 \\
  0 &amp; 0 &amp; 1 &amp; 1
\end{pmatrix}$
Thus only 4 error terms would continue onto earlier layers.
Convolutional layers
I have gone in detail about how to do backpropagation through convolutions here: CNN backpropagation between layers.