Let the lengths of the sides of square be $b$ and the sides of octagon be $a$.
Given: $4b=8a$
$ \implies b=2a$
A regular octagon can be divided into $4$ triangles and $1$ square .
$\newcommand{deg}{\,^\circ}$
Area of the square within the octagon can be calculated as follows: $$\begin{align}
&\Bigl ( 2a \cos{(22.5\deg)} \Bigr ) \times \Bigl ( 2a \cos{(22.5\deg)} \Bigr )\\[1em]
&= 4a^2 \cos^2{(22.5 \deg)}\\[1em]
&= 4a^2 \sin^2{(67.5 \deg)}\\[1em]
&= 2a^2 \Bigl (1 - \cos {(135 \deg)} \Bigr ) \qquad \Bigl \{\sin^2 x = \frac{1- \cos{2x}}{2}\\[1em]
&= 2 \times a^2 \Bigl (1 + \sin{(45\deg)} \Bigr )
\end{align}$$
Area of the triangle can be calculated as follows: $$\begin{align}
&2 \times \frac{1}{2} \Bigl (a \cos{(22.5\deg)} \times a \sin{(22.5\deg)} \Bigr )\\[1em]
&= \frac{a^2 \sin{(45\deg)}}{2} \qquad \Bigl \{ \sin{2x} = 2 \sin x \cos x\\[1em]
&=\frac{a^2 \sin{(45\deg)}}{2}
\end{align}$$
Area of $4$ triangles $= 2 \times a^2 \sin{(45\deg)}$
$\therefore$ Area of the octagon $= 2a^2 + 2a^2 \sqrt{2}$
Ratio of area of octagon to area of square: $$\begin{align}
&= \frac{2a^2 + 2a^2 \sqrt{2}}{b^2}\\[1em]
&= \frac{2a^2 + 2a^2 \sqrt{2}}{4a^2}\\[1em]
&= \frac{1 + \sqrt{2}}{2}
\end{align}$$