Emeralds form deep within the Earth's crust when beryllium, aluminum, silicon, and oxygen combine under high pressure and temperature, with trace amounts of chromium or vanadium giving the gem its green color. This process occurs over millions of years, often facilitated by hydrothermal fluids that deposit the necessary minerals.