The most accurate way is called body plethysmography. You sit in a clear airtight box that looks like a phone booth. The technologist asks you to breathe in and out of a mouthpiece. Changes in pressure inside the box help determine the lung volume.
Lung volume can also be measured when you breathe nitrogen or helium gas through a tube for a certain period of time. The concentration of the gas in a chamber attached to the tube is measured to estimate the lung volume.