There is an android specification for the configuration of headset buttons. The functions are interpreted by a voltage detected on the microphone ADC. Full details for necessary hardware values and configuration are in the linked article.
The 3 buttons that are available on all devices are:
- Play/pause/hook (Short Press), Trigger Assist (Long Press), Next (Double Press)
- Volume +
- Volume -
There is a 4th button option specification, but it appears to be "Reserved (Nexus devices use this to launch voice commands)."
While the technical potential is near infinite if you are capable of doing hardware and software modifications, the practical easy answer is 3 or 4.