How it is calculated
Margin = lots × contract size of 1 lot × price × the rate to your account currency ÷ leverage.
The part before the division sign is the value of the whole position in your account currency. Leverage of 1:500 means you only have to hold 1/500 of that value, which is 0.2%. The contract size of 1 lot is 100,000 units of the first currency in the pair; for gold it is 100 ounces.
Examples
EURUSD at 1.17, 0.1 lots, leverage 1:500, USD account: 0.1 × 100,000 × 1.17 = 11,700 USD of position value; ÷ 500 = 23.40 USD of margin.
USDJPY, 1 lot, leverage 1:100, USD account: the position is worth 100,000 USD whatever the price; ÷ 100 = 1,000 USD of margin.
XAUUSD at 2,000, 0.1 lots, leverage 1:100: 0.1 × 100 × 2,000 = 20,000 USD; ÷ 100 = 200 USD of margin.
Margin is not the most you can lose. Profit and loss run on the value of the whole position: higher leverage makes the margin smaller, it does not make the risk smaller. See the guide on what leverage is and how much of it to use.