The reason this trick works is due to the air sac inside the egg. As the egg ages, the air sac gets bigger, making the egg more buoyant. So, when you put it in water, the egg will either sink or float, depending on the size of the air sac. It's like the egg is getting a little "inflated" with age!
But don't worry, this trick isn't egg-acting science - it's actually pretty straightforward. Just make sure the water is cold, as this will help the egg sink or float more predictably. And if you're feeling extra adventurous, you can even use this trick to test the freshness of multiple eggs at once - just be careful not to crack under the pressure!