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 :
O. S is a theoretical concept. Electrons shared between two unlike atoms are counted towards more electronegative element.
Nitrogen cannot exhibit a +5 oxidation state due to the absence of d-orbitals.
PROOF: Quantum Mechanics basics
As Nitrogen is in 2nd period in the modern periodic table, principal quantum number being n=2, the Azimuthual Quantum numbers = 0 to n-1
for Nitrogen it ranges from 0 to 1.
0 (zero) represents an s orbital and 1 represents p orbital hence no D orbitals are there.
... which clearly tells us that due to absence of d orbitals, nitrogen cannot expand its oxidation state greater than 4. Hence by the basic principle of quantum mechanics we can say that in N2O5 nitrogen has +4 oxidation state.
NOTE: Formulae are made to simplify the things. But they have some limitations But in order to overcome those limitations one must use the basics of the subject.