Your saws manufacturer will be able to tell you the largest bar your saw will run with. As a rule of thumb I would use a bar 2 inches shorter than the manufacturers recommended maximum.e.g. if your saw can run with a 22 inch bar then the max I would use would be a 20. This means the saw isn't working at it's limits all the time and will last longer and work more efficiently.
If you need a larger bar than your manufacturers max recommended length,then you need a bigger saw.