Unfortunately, there's no easy way to post mathematical formulas here.

The possible number of addresses in a network is given by 2 to the power of the number of bits that can vary. Through algebra, you can show that the number of bits needed for a given number of addresses is the base 2 logarithm of the number of bits. This is sometimes abbreviated to 'lg'.

Google:

lg(512). That should give you the answer of nine, which is how many bits have to vary.

You then set the last 9 bits of a 32bit sequence to zero:

11111111111111111111111000000000

Split it into 4 groups of 8 bits:

11111111 11111111 11111110 00000000

Convert each byte into decimal:

255 255 254 0

And dot it:

255.255.254.0