Assuming that you are acquiring brackets that are strong enough and stiff enough to carry the loads, the question of how long brackets need to be is a good one (though not really a woodworking question).
One consideration is whether you intend to simply place the shelf on the bracket and let gravity keep it in place. If that is the case, your bracket should extend nearly the full depth if the shelf to remove any chance of a heavy load (e.g. you hanging from it by your finger-tips) causing the shelf to tip forward and spilling its contents.
A more practical approach would be to get a bracket having a top arm about 3/4 of the shelf depth, and screw the shelf to the bracket. If the bracket has more than one hole and you want to use fewer than the full complement of screws, it is imperative that you use the hole nearest to the wall just to avoid the calamity of too much load near the front edge.
As far as attaching the bracket to the wall, it is best not to skip any of the holes, but the most important one is the top one, again to withstand excessive moment causing the shelf and bracket to fail.