Mountain bike sizing is not an exact science. Compared to road cycling, for example, there are many factors that can influence what size bike riders should choose. Constantly changing terrain means that nothing is constant when mountain biking, so your position on the bike is constantly changing, too.
There are, however, some general guidelines and measurements to consider when deciding what size bike to buy. One of the contributing factors that determine bike size is rider height. After all, most mountain bikes are designed to be pedaled in a seated position, and a rider's height will largely determine if this position is comfortable, or not.
An important bike measurement related to height is the standover height. This is how far the top tube of the bike is from the ground and can be compared to a rider's inseam. A rider's inseam should be a larger number than the standover height of the bike. Another way to think of this is that a rider should be able to comfortably stand flat-footed on the ground while straddling the bike. If there isn't enough of a gap between the top tube and the rider's inseam, the bike is too big.
Another measurement related to height is the seat tube length. This determines how high or low the saddle can be. If a tall rider is on a bike that's too small, with too short of a seat tube, the saddle won't be able to go high enough.
Reach and top tube length are other important measurements. Reach refers to the distance between the center of the bottom bracket and the head tube. This is essentially how far the rider is from the handlebars when they are standing up on the bike. The effective top tube length, also shortened to top tube length sometimes, is the distance between the head tube and the seat tube. This is how far the rider is from the bars when they are seated.
A taller rider will need a bike with a larger top tube and reach numbers, while a smaller ride will need smaller numbers.
This may all seem confusing, which is why bike companies offer multiple sizes of bikes, which feature different measurements. For comparison, let's take a look at the geometry of the Santa Cruz Megatower, one of the best enduro bikes on the market.
On the Megatower, the reach on a size small is 425mm and the top tube length is 567mm. On a large, the reach is 470mm and the top tube length is 619mm. For the small, the standover height is 702mm, while the large is 713mm.
Bike brands usually recommend a size based on the rider's height. For example, in Santa Cruz's case, a person that's 1.57-1.65m will need a size small, whereas a person who's 1.75-1.85m will ride a large.
The best way to figure out if a bike fits is to visit a bike shop. Try the size that best corresponds with your height, and see if it is comfortable. Bike shop employees are usually trained to assist with this as well.
Riding style can also influence bike fit. Height isn't always perfect, with many people falling in between sizes. For example, according to Specialized's size guide for its Enduro model, a person that's 1.85m could fit on a size S4 or an S5.
This is where geometry numbers like wheelbase come in. The wheelbase is the distance between the front and back wheel. A longer wheelbase leads to more stability, while a shorter wheelbase is more agile and maneuverable.
If a rider wants to race and therefore is looking for stability at speed, they would choose a longer wheelbase bike (S5). If someone wants to do lots of jumps and hits, a shorter wheelbase would be ideal (S4). That's the idea behind Specialized's sizing system. Two riders that are the same height can tailor their bike size to the style of riding they want to do.
Once a size is chosen, there are tons of other ways to improve the fit and comfort of a bike. These are crank length, saddle height, saddle angle, cleat position, and stem length.
For instance, a cross-country racer may want a longer, lower stem for a lower, more aerodynamic position. An enduro rider will want a shorter stem and higher bars for more stability and control on the steep descents.
It's quite easy to go down the rabbit hole on this stuff, and lots come down to personal preference. However, bike fit can be dialed in relatively easily by visiting a bike fitter. A bike fitter can ensure that your seated riding position is comfortable by measuring and adjusting attributes such as saddle height and cleat position.
Unfortunately, the best way to find what works for you is to test multiple bikes. Some shops offer test rides or demo events to try out different bike sizes. This way you can see how a particular size actually performs on the trail.