If a legitimate ball passes the batsman without touching his bat or his body, any runs completed are credited as 'byes'.
If a legitimate ball misses the bat but touches the batsman's body, any runs completed are credited as 'leg byes'.
Runs completed off a bye or leg bye, including boundaries, are added to the extras tally of the batting team but they are not credited against the bowler.
In order for a leg bye to be awarded, the umpire must deem that the batsman either attempted to play a stroke or tried to avoid being hit by the ball.
If the umpire considers that the batsman did neither of these then a dead ball is called and no runs can be scored.