if a piece of music is 4/4 why sometimes are there 5 notes to the bar
It's because you can have something other than four quarter notes in the measure.
Example, count: "one . . . two . . . three-and-four", or the old marching cadence: "left, left, left right left."
If each word is a "note", then that's 5 "notes" over four beats. The one, two and four are quarter notes, and the "three-and" are eighth notes.
I think this is the same thing Russell said, but I'm not sure. Examples made it easier for me to understand.