youcubed Task 7: 36 Fences
The biggest pen you can build
November 23, 2026
Task 7 of 8 in the youcubed Portal, a series on tasks from Jo Boaler's youcubed center at Stanford. The task is youcubed's; the explanations and practice problems are written for Math Thinking Coach.
You have 36 pieces of fence, each one meter long. What's the largest area you can enclose?
youcubed leaves one decision to the class: are only rectangles allowed, or any shape at all? It's worth trying it both ways.
Rectangles only
A rectangle with a perimeter of 36 has a length and width that add to 18. Try them all:
1 × 17 = 17
3 × 15 = 45
5 × 13 = 65
7 × 11 = 77
8 × 10 = 80
9 × 9 = 81
The skinny rectangles waste fence. The closer the shape gets to a square, the more area it holds, and the 9-by-9 square wins at 81 square meters.
Notice something else in the list: as the rectangle gets closer to square, the area gains get smaller (77, 80, 81). The top of the curve is flat. That idea comes back in calculus.
Any shape allowed
Now the class allows other shapes, and things get interesting:
An equilateral triangle with 12-meter sides: about 62 square meters, worse than the square
A regular hexagon with 6-meter sides: about 94 square meters
A circle with a circumference of 36 meters: about 103 square meters
With straight one-meter pieces you can't make a true circle, but you can make a regular 36-sided shape, and it holds about 102.9 square meters, almost exactly the circle's area.
The general principle: for a fixed perimeter, the more sides a regular shape has, the more area it encloses, and the circle beats everything. It's why soap bubbles are round, and why the ancient legend of Queen Dido, founder of Carthage, who was offered as much land as an oxhide could enclose, has her cut the hide into thin strips and lay them out in a great curve.

Why Boaler loves it
36 Fences is listed for grades 2 through 12. Young students can build pens with snap cubes on grid paper and count squares. Middle schoolers can make a table and spot the pattern. High school students can use trigonometry to find the area of any regular polygon, or dynamic geometry software to test irregular shapes. Everyone works on the same question at their own level.
It's also a classic optimization problem: getting the most from a limited resource. Optimization is one of Ted Dintersmith's eight pillars of useful math in The Ted Dintersmith Portal, and this is one of the friendliest ways in.
Try it yourself
A farmer has 36 meters of fence and builds a rectangular pen against the side of a long barn. The barn wall forms one side, so no fence is needed there. What dimensions give the biggest pen?
Answer: Call the two sides that touch the barn w each, and the side opposite the barn L. Then 2w + L = 36. Try a few:
w = 6, L = 24: area 144
w = 8, L = 20: area 160
w = 9, L = 18: area 162
w = 10, L = 16: area 160
The best pen is 9 meters deep and 18 meters along the barn, 162 square meters. Notice it's exactly half of an 18-by-18 square. Think of the barn wall as a mirror: the pen plus its reflection is the best possible rectangle for 72 meters of fence.
Go deeper
The full task is at youcubed: 36 Fences.
Next in the series: Task 8: Data Talks