What is the size of each side of the square?

enter image description here

Join the center of the bigger circle (radius assumed to be $r$) to the mid-points of the square. It’s easy to see that $ABCD$ is a square as well. Now, join the center of the big circle to the center of one of the smaller circles ($P$). Then $BP=r+1$. Further, if we draw a vertical line through $P$, it intersects $AB$ at a point distant $r-1$ from $B$. Lastly, the perpendicular distance from $E$ to the bottom side of the square is equal to $AD=r$. Take away three radii to obtain $EP=r-3$. Using Pythagoras’ Theorem, $$(r-1)^2 +(r-3)^2 =(r+1)^2 \\ r^2-10r+9=0 \implies r=9,1$$, but clearly $r\ne 1$, and so the side of the square is $2r=18$.


It is instructive to consider the general case. Suppose we have a circle of radius $r$ that is inscribed in a square of side length $2r$. Suppose $n$ tangent circles of unit radius can be drawn along the inside "corner" of the square. What is the relationship between $r$ and $n$? Your question is the case $n = 2$, the third circle drawn in the corner being redundant. The figure below illustrates the case $n = 5$:

enter image description here

The solution is straightforward. The right triangle shown in the diagram has legs $r-1$ and $r-(2n-1)$, and hypotenuse $r+1$. Therefore, $$(r-1)^2 + (r-2n+1)^2 = (r+1)^2,$$ from which it follows that $$r = (1 + \sqrt{2n})^2.$$ For $n = 2$, this gives $r = 9$ and the side length of the square is $18$. For $n = 5$, we have $r = 11 + 2 \sqrt{10}$. Whenever $n$ is twice a square, i.e. $n = 2m^2$ for a positive integer $m$, then $r = (1 + 2m)^2$ is also an integer and the circumscribing square has integer sides.


As a related but different question, given $n$ such circles, what is the total number of externally tangent unit circles that can be placed in the corner such that their centers form a square lattice and do not intersect the large circle? So for $n = 2$, this number is $f(n) = 3$ as shown in your figure. For $n = 5$, it is $f(5) = 12$.


In the diagram below point $D$ is at $(3,1)$ and $E$ is at $(1,3)$ We have a right triangle using $G, D$ and the intersection of $GI$ and $DE$. Let the radius of the large circle be $r$, which is half the side of the square. Then $GD=r+1$, $D$ to the intersection is $\sqrt 2$ and $G$ to the intersection is $(r-2)\sqrt 2$ $$(r+1)^2=(\sqrt 2)^2+((r-2)\sqrt 2)^2\\ r^2+2r+1=2+2(r^2-4r+4)\\ 0=r^2-10r+9\\ r=1,9$$ and clearly $9$ is the root we want. The side of the square is $18$

enter image description here