Turns out the way the cookie crumbles has an awful lot to do with science.

As part of Beakerhead events going on throughout the city this weekend, Calgarians are getting a chance to learn from chemists about the science behind the perfect chocolate chip cookie at Crave bakery in Kensington.

"The perfect chocolate chip cookie is actually a very complex mixture of all the different ingredients that you use, as well as the ratios that they are used in," said Natasha Garner, a doctoral candidate at the University of Calgary.

"I think baking is a lot like chemistry in the fact that you really want to make sure you are following a recipe because those amounts do make a difference. You really want to have a consistent batter every time."

What makes the perfect cookie? The Homestretch's Jenny Howe taste-tested several different cookies, each one unique thanks to switching up the types and amounts of sugar, types of fats, and the leavening ingredients. 

And the winner? Crave owner Carolyne McIntyre Jackson revealed the secret of Howe's favourite.

 "(For) the perfect chocolate chip cookie at Crave we use butter, and then we actually do half brown sugar, half white sugar," she said.

The recipe is on Crave's blog.

Garner says it's not just the ingredients that make a cookie perfect.

"They know exactly the right ratio of these ingredients, they know the exact bake time, the exact amount of time to mix the butter and the sugars together. Really it's that ratio that makes the cookie."