بسم الله الرحمن الرحيم
when I thought about this problem, I concluded this rule :
Nbre of Square= SUM(i²) [i from 1 to j] ; with j=Nbre of smallest squares which build costa of the large Square
For Example : we have in the picture j=4
So : Nbre of Square = 4*4+3*3+2*2+1*1=30 squares
so When we have j=5 .