Let the garden dimensions be x (the length) and w (the width). Then w = x - 8 and together with the sidewalk it forms a larger rectangle whose length is x + 8 (add twice the width of the sidewalk) and the width is x (add twice the width of the sidewalk to the original width, w + 2*4 = x - 8 + 8). The area of the sidewalk is the difference of the areas of the larger rectangle, (x + 8)x, and the smaller rectangle, x(x - 8). Thus,
(x + 8)x - x(x - 8) = 320; open the parentheses
x^2 + 8x - x^2 + 8x = 320; simplify
16x = 320; x = 20
Answer: the length of the garden is 20 ft and the width is 12 ft.