Step 1:

Let $x,y $ be the length and breadth of a rectangle. Whose permeter is the given value P

$\therefore\; 2(x+y)=p=>y=\large\frac{p}{2}$$-x$

The sides of the rectangle are $ x, \large\frac{p}{2}$$-x$

Step 2:

The area of the rectangle is

$A=x \bigg (\large \frac{p}{2}$$-x\bigg)=\large\frac{px}{2}$$-x^2$

Step 3:

At extreme values of $A, \large\frac{dA}{dx}$$=0$

$\large\frac{dA}{dx}=\frac{p}{2}$$-2x$

$\large\frac{p}{2}$$-2x=0=>x=\large\frac{p}{4}$

$\large\frac{d^2p}{dx^2}$$=-2 <0=>x =\large\frac{p}{4}$

Corresponds to a maximum value of A.

$\therefore$ the area is maximum when the sides are $\large\frac{p}{4},\frac{p}{4}$ .

The sides are equal => this is a square