The solution to John of Palermo's problem requires several steps and some of the most intricate work in The Book of Squares. The first step seems at first to be unrelated:
If two numbers are relatively prime and have an even sum, and if the triple product of the two numbers and their sum is multiplied by the number by which the greater number exceeds the smaller number, there results a number which will be a multiple of twentyfour [p. 48].
Leonardo often represents numbers as lengths. Here he considers points a, b, and g on a line, with the two numbers being the lengths from a to b and from b to g. Thus, in our notation, the expression under discussion is

ab

· 
bg

· ( 
ab

+ 
bg

) · ( 
bg

 
ab

), 

assuming that ab and bg are relatively prime with bg > ab. Leonardo proves this product is a multiple of 24 by carefully checking cases. He calls the numbers obtained from this kind of product congruous.
The purpose of the congruous numbers is shown a little later while addressing the following problem:
Find a number which added to a square number and subtracted from a square number yields always a square number [p. 53].
This is John of Palermo's problem except it does not require the number to be 5. Let us continue using ab and bg as before. We throw in the additional condition that bg·(bg  ab) < ab·(ab + bg), which will keep us in the realm of positive integers in what follows. Leonardo's method involves the bg·(bg  ab) consecutive odd numbers centered at ab·(ab + bg) and also the ab·(bg  ab) consecutive odd numbers centered at bg·(ab + bg). In the example given in the book, ab = 3 and bg = 5, so we get 10 consecutive odd numbers centered at 24:
15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 

and also 6 consecutive odd numbers centered at 40:
These two sequences have an amazing relationship. They are next to each other in the list of all odd numbers, and they have the same sum, 240, which is the congruous number ab·bg·(ab + bg)·(bg  ab) = 3·5·8·2. Thus,
17^{2}  240 = (1+3+ ... + 33)  (15 +17 + ... + 33) = 1+3 + ... + 13 = 7^{2}, 

and
17^{2} + 240 = (1+3+ ... + 33) + (35 + 37 + ... + 45) = 23^{2}. 

This solves the problem. Now, how can Leonardo use this idea with 5 instead of 240?