I knew the desk surface was 24" deep, and that I needed space around the edge to clamp things on. So, I set the maximum support length at 20". To keep things simple, I decided to make the supports perfect right triangles (90-45-45), so the section screwed onto the wall had to be 20" as well. But, that measure is only a guide.
The section (1) that runs along the underside is actually 18.5", due to the thickness (about 1.5") of the horizontal support already mounted to the wall. The section mounted directly to the wall (2) is only 16.5", due to the width of the 2x4 (about 3.5"). And of course the angled section (3) can be calculated from there. I chose a length of 21.5", a length that placed the angled section about 1" from the ends of the wall and desk sections.
A fourth piece (4) supports one end of the section that runs along the underside of the desk, and provides a convenient place to drive in more screws. It also joins the horizontal support to the wall section, adding additional redundancy.
I should note that being super-accurate here really isn't necessary. There will be no complex joinery here, and no piece relies on any other piece for a perfect fit. So don't beat yourself up about an eighth of an inch here or there.
So, how many supports do you need? Make sure there's one on each end of the desk for starters. In my case, one end of the desk was supported by the horizontal support screwed onto the wall, so one support was placed as close to the other end as the studs would allow. Then just place the supports 32" apart from there. Again, this will depend on how long the desk is. In total, I needed six sets of supports for desk top that is 8 feet on one side and seven on the other.
A miter saw is all you need to cut the 2x4 lumber into sections. Pieces 1, 2, and 4 were cut with a 90 degree cut on one end, and a 45 degree bevel on the other. The bevel looks nice for one thing, but also prevents bruised knees. Piece 3 was cut with a bevel on both ends, since it will be screwed on at an angle to the others. Cut one set to test for fit, then cut the rest.