According to the formula it should be +5 but according to its structure shouldn't it be +4? How is it +5 then?
It is +5 .Even by the structure.
Notice that it is a resonance structure of:
Now one of the bonds are coordinate bonds where nitrogen donates BOTH its electrons to oxygen (otherwise, oxygen cannot have a single bond without a negative charge and no peroxy type linkage).
So, while determining oxidation state from the structure :