It is forbidden on a holiday to do any act in preparation for the following day, even if the following day is Shabbat. However, the sages created a halachic device, called an eruv tavshilin, which allows one to cook food on a holiday day for use on a Shabbat that immediately follows it.
If a holiday day -- whether the first or second day of a holiday -- falls on a Friday, an eruv tavshilin is set aside on the day preceding the holiday (Wednesday or Thursday afternoon), so that we will be permitted to prepare for Shabbat (cooking as well as any other necessary preparations) on the holiday. Only one eruv is required per household.
This eruv consists of a challah or two matzahs, and a cooked food, such as meat, fish, or an unpeeled hard-boiled egg.
Take the food items (it is a good idea to wrap them in aluminum foil, or another distinctive packaging, to easily keep them apart from the rest of the foods in your home), and give them to another person (if possible an individual who is a non-dependant), and say:
I hereby grant a share in this eruv to anyone who wishes to participate in it and to depend on it.
The one holding the food raises it a handbreadth, and then returns it to the person making the eruv, who then recites the following:
Blessed are you, L-rd our G‑d, king of the universe, who has sanctified us with his commandments, and commanded us concerning the mitzvah of eruv.
Through this [eruv] it shall be permissible for us to bake, cook, put away a dish [to preserve its heat], kindle a light, prepare, and do on the holiday all that is necessary for Shabbat -- for us and for all the Israelites who dwell in this city.
The eruv is put away until Shabbat, when it is eaten. In many communities, it is customary to use the challah or matzah as one of the two loaves of bread used at the Shabbat meal.
- The eruv tavshilin only allows food preparations if the food will
be ready with ample time remaining before Shabbat; enough time to
theoretically allow the food to be consumed before sunset (if a troop of
guests happens to trudge in to your home). This is an importnat detail to
bear in mind when preparing the cholent, which cooks on the stove
until the following day.
- The eruv tavshilin only allows one to cook on Friday for Shabbat, it does not permit cooking from one day of the holiday to the next (i.e. Thursday for Friday).
- On holidays it is only permissible to cook from a pre-existent flame, one that is burning since the onset of the holiday.
Click here for more on eruv tavshilin.