Well I can only say for Airbus aircraft, but you have 2 ways of knowing how much fuel you have in the tank.
1) On the ground there are magnetic level indicators which are like a dipstick on a car, only they have a float which is magnetic and lifts your 'dipstick' up and down.
2) The fuel gauging system. Here you have a few (around 30 on an A320) low voltage capacitors where the fuel can go between them. At a different fuel level you will have different capacitances (i.e. capacitance proportional to the height of fuel) and therefore you know where your level is at. For the aircraft pitch and roll attitudes the fuel computer works out a plain of whee the fuel is (slightly different on different manufacturers). Additionally to that you have a density and permittivity readers in the tank to then calculate the fuel quantity (either kg or lbs).
Then you have level sensors. These have two states they know, either 'wet' or 'dry'. So they are placed at known levels in the tank (high level, low level etc) so these will trigger certain valves and warnings.
Hope this explains it somewhat!