In historical terms, a legacy is something that is handed down from one period of time to another period of time. A historical legacy can be counted in later times as a good thing or a bad thing. For example, the invention of the wheel (for carts, as a potter's wheel, as a millstone to help turn grain into flour, and as an early water wheel) in Mesopotamia can be seen as something good. The development of slavery is a bad legacy.
Sometimes countries or civilizations can leave a legacy that will be remembered for a long time. Buddha and Confucius left moral legacies. More than 2000 years ago the Greek Mathematician, Euclid of Alexandria, collected and wrote down ideas about geometry and measurement in a text called Elements. Students still use these ideas when they learn about mathematics. In Athens, citizens voted on what the city would do. This early form of democracy is a cultural legacy.
Some families pass objects and ideas down from generation to generation. These heirlooms and ideas can also be called legacies. It may have to do with a person or many people. Individuals can leave a historical legacy.
Legacies are, more or less, what we remember about a person or a country. What an individual or a country does today might, in the future, be regarded as being important enough to be thought of as a memorable legacy from the 21st Century.
Legacy is a similar concept as inheritance and heritage. It is something we inherit from past generations and pass to our future generations. Usually heritage refers to material and economical inheritance, while legacy refers to immaterial and cultural inheritance.
When software source code is reused in new software development, the old code is often called legacy code.