Since selling price is more than cost price, so it's a gain case.
To find the gain percentage the formula used is :- ((S.P - Ç.P)/Ç.P)*100
Where S.P =Selling Price
Ç.P. =Cost Price
As it's a gain case (or S.P>C.P) therefore numerator is S.P - C.P.
Putting values:- ((500-400)/400)*100
((100)/400)*100)
(100/4)
25% gain.