Cooking the perfect boiled egg is sometimes harder than it seems. Sometimes the egg whites are too chewy or the yolk is too dry or the egg sticks to the shell making it impossible to peel.

That’s because an egg actually consists of two different substances. You have to boil the white and the yolk at different temperatures to achieve the desired texture. The right temperature for an egg white is 180°F (82°C), and for a yolk it’s 170°F (77°C).

American chef J. Kenji López-Alt turned to science to find the best way to boil eggs. He put a bunch of eggs in boiling water for 30 seconds, then added a few ice cubes to bring the temperature down. Every 30 seconds he took one egg from the water to check the consistency.

Here are the results: