An airline can legally keep you on a plane for up to 3 hours for domestic flights and 4 hours for international flights unless the pilot or air traffic control deems it would be unsafe for you to deplane.
In those cases the airline can keep you on the plane much longer.
Airlines can make you sit on a plane for 3 hour for domestic flights and 4 hours for international flights.
After 3 hours for domestic flights and 4 hours for international flights, the airline must allow you a chance to get off the airplane, unless there are any safety, security or air traffic control reasons for not allowing you off the plane.
During any Tarmac and airline delays where you're on the plane and delayed, the airlines must also provide you with adequate food and water and the airline must also allow you to use the toilet and the toilet facilities must be maintained and available to all passengers.
Airlines should also keep any passengers informed about the situation during the tarmac delay.
Although if the pilot determines that deplaning would jeopardize passenger safety or security, or if air traffic control advises that it would disrupt airport operations significantly then the pilot can keep the passengers on the plane longer.
The 3 hour rule is for domestic flights and 4 hour rule is for international flights.
And if you have not been offered any food or water within the first 2 hours, then you can politely remind the flight attendants of the airline's obligation for food and water.
And if you're held for any excessive time period, ask the flight attendants how the airline plans to fix the situation.