The equation density = mass ÷ volume can be rearranged. Mass = density × volume, and volume = mass ÷ density. Use it with mass in kg, volume in m3 and density in kg/m3.
When a substance is compressed, or changes state, its mass stays the same. Mass is conserved. The particles are only spread out or squeezed together. The volume changes, so the density changes too. If the same mass takes up a smaller volume, the density becomes higher.
Example: 0.060 kg of gas in a volume of 0.050 m3 has density 0.060 ÷ 0.050 = 1.2 kg/m3. Squeeze it into 0.020 m3 and the mass is still 0.060 kg, so the density is 0.060 ÷ 0.020 = 3.0 kg/m3.