As many as the fielding team takes to get out the batters or until the batting team declares.
If there are no extras, then only 30 balls will be bowled. If there are extras, more balls will be bowled depending on the number of extras.
there are 6 balls per over in cricket, unless a wide or no ball is bowled
In a test match 90 overs a day so 540 a day so times 540 by 5 so that it 2700 ball in a test match.
By illegitimate, I presume you refer to a no-ball or a wide. Under current rules an over contains 6 balls. Some years back, 8-ball overs were used in Australia if nowhere else. For an over to be complete, 6-balls not including a wide or no-ball must be bowled. If an illegitimate ball is bowled, it must be rebowled. The most illegitimate balls bowled in one over was an over bowled by Curtly Ambrose in his final test on Australian soil which contained 9 no-balls - a total of 15 balls.
Six legal balls are bowled in a single over. The rule has changed over time; in the past there were eight balls in an over.
for each match they give the match 500 balls in the huge buckets
There are six legal balls bowled in one over, meaning that their has to be six balls which are not deemed to be no balls or wides.
There are no specified overs in a test match. It is usually 5 days of cricket with around 90 overs bowled on each day. Things like rain delay, bowling team bowling slow etc can affect the number of overs bowled in a test match.