Muscles works in both cases but it’s seems difficult to understand that how they work
The expression of emotion is a complex thing and the answer to this is somewhat dependent on the variation within the individual. There are a little over 40 muscles in the human face, including the orbicularis oris (muscle around your mouth), the risorius (that pulls the corners of the mouth backwards) and the temporalis (the mouth muscle used for chewing). Due to the complexity of these muscles and those that contribute to a smile or sad face, there is likely quite a bit of variation in the muscles that are required for each. I have heard however that it takes approximately 43 muscles to frown and 17 to smile, which may make sense given the fact that a smile is only a slight deviation from a "resting" facial expression.
Hope this helps!