Let's denote the cost of each bag of popcorn as \( p \).
Sam bought one soft drink for $2 and 8 bags of popcorn, spending a total of $34. We can set up the equation based on this information:
\[ 2 + 8p = 34 \]
Now, we need to solve for \( p \). First, we can isolate the term with \( p \) by subtracting 2 from both sides of the equation:
\[ 8p = 34 - 2 \] \[ 8p = 32 \]
Next, we divide both sides by 8 to find the cost of each bag of popcorn:
\[ p = \frac{32}{8} \] \[ p = 4 \]
Therefore, each bag of popcorn costs $4.