In The U.S., under part 121 rules it is mostly based on flight time. Only 2 pilots are required up to 8 hours of flight time. If you have 3 you can fly up to 12 hours and anything above that requires 4. Also many company or union rules may be more restrictive.
Not having worked for a non US airline airline I will let someone else comment but I have seen the rules vary quite a bit from country to country.