A method for converting a solid carbonaceous fuel into flue gas and ash in a thermal reactor, said method comprising heating the fuel at separate stages to temperatures causing the fuel to decompose into gaseous and solid components, the stages comprising - a drying stage in which the fuel is heated to a temperature of 400°C or above, and means for feeding fuel to the drying stage, - a pyrolysis stage in which the fuel is heated to a temperature of 500°C or above, in which the fuel is pyrolysed without addition of oxygen, - a gasification and oxidation stage wherein the temperature is between 600°C-1100°C, in which char is converted to burnable gas and carbon-rich ash, - an ash burn-out stage to which air is supplied wherein ash is burned to a carbon content below 10% on a weight basis and wherein the ash is cooled to a temperature below 300°C, and - a gas combustion stage to which air is supplied to convert the combustible gasses into CO 2 and H 2 O and wherein temperature is between 700°C-1100°C, wherein - the means for feeding fuel to the drying stage is arranged to feed dried fuel from the drying stage onto the pyrolysis stage, - the pyrolysis stage is immediately above the gasification and oxidation stage, - the fuel at the pyrolysis stage is heated by means of the gases formed in the gasification and oxidation stage and the gas combustion stage, - the drying stage, the pyrolysis stage and the gasification and oxidation stage and the ash burn-out stage form an updraft gasifier and are carried out in an updraft moving bed reactor, and - the gas combustion stage is above the updraft gasifier where the gases from the updraft gasifier are burned and heat from the gas combustion is transferred to the top layer of fuel in the updraft gasifier, wherein the gas combustion process is carried out 4 metres or below from the bed surface, wherein - the stoichiometric ratio of the thermal reactor is 1.2-1.3 and the gasification operates with a stoichiometric ratio of 0.2-0.25. - a drying stage in which the fuel is heated to a temperature of 400°C or above, and means for feeding fuel to the drying stage, - a pyrolysis stage in which the fuel is heated to a temperature of 500°C or above, in which the fuel is pyrolysed without addition of oxygen, - a gasification and oxidation stage wherein the temperature is between 600°C-1100°C, in which char is converted to burnable gas and carbon-rich ash, - an ash burn-out stage to which air is supplied wherein ash is burned to a carbon content below 10% on a weight basis and wherein the ash is cooled to a temperature below 300°C, and - a gas combustion stage to which air is supplied to convert the combustible gasses into CO 2 and H 2 O and wherein temperature is between 700°C-1100°C, - the means for feeding fuel to the drying stage is arranged to feed dried fuel from the drying stage onto the pyrolysis stage, - the pyrolysis stage is immediately above the gasification and oxidation stage, - the fuel at the pyrolysis stage is heated by means of the gases formed in the gasification and oxidation stage and the gas combustion stage, - the drying stage, the pyrolysis stage and the gasification and oxidation stage and the ash burn-out stage form an updraft gasifier and are carried out in an updraft moving bed reactor, and - the gas combustion stage is above the updraft gasifier where the gases from the updraft gasifier are burned and heat from the gas combustion is transferred to the top layer of fuel in the updraft gasifier, wherein the gas combustion process is carried out 4 metres or below from the bed surface, - the stoichiometric ratio of the thermal reactor is 1.2-1.3 and the gasification operates with a stoichiometric ratio of 0.2-0.25.