The original pattern probably said something about Tension or Gauge. It would say Tension [or Gauge]: 26 X 32 = 10cm/4". The first number is the amount of stitches across, and the 2nd number is the amount of rows up and down to equal a 10cm X 10cm square (which is also 4" X 4"). Often they leave out the 2nd number, and even if it's there, it usually doesn't matter too much. The first number however, is very important.
They probably also gave you the needle size to use, which apparently was 5mm. But the needle size is only a recommendation-- you use whichever size gives you the correct gauge. To swatch, you cast on more than you need, in order to get a good measurement. So I'd cast on 26 plus 4 sts on each side, which would be 34. Then knit for about 4", and then measure 26 sts in the center of the piece, while it's laying flat. That should be 4" across. If it's too big, then reduce your needle size and try again. If it's too small, use bigger needles. Keep doing this until you get the 26 sts equalling 4". (I just picked 26 sts out of the blue-- your hat probably had some other number, which is what you should use.)