The answer strongly depends of the intended accuracy, the nature of the numbers and the type of text. My private rule of thumb is the following:
For scientific texts, manuals, etc., I would write out 1 to 12, if they are natural numbers (in contrast to real numbers), and nothing else.
Seien a und b zwei Elemente der Menge X. – Let a and b be two elements of the set X. (Natural number)
Die Probe wurde 5 Stunden gekühlt. – The sample was cooled for 5 hours. (Real number)
However, I would not write out cardinal numbers that refer to an enumeration system:
In Kapitel 5 … (cardinal number, enumeration system)
Aber: Im fünften Kapitel … (ordinal number, enumeration system)
Das Elektron hat die Nebenquantenzahl 2. (cardinal number, enumeration system)
Finally, I would not write out any natural numbers that are followed by an abbreviated unit:
Die Schlüsselgröße ist 8 B.
Aber: Der Schlüssel ist acht Byte groß.
In stories, poems, etc. I would additionally write out 1, 1.5 and 2 to 12 as well as 20, 30, …, 100, 200, …, 1000, …, if they are vague information. As a rule of thumb for everything beyond 12: If x could be replaced by x+1 (ignoring the correctness of the information), do not write x out.
Er ist ungefähr dreißig Jahre alt. – He is about thirty years old.
(His actual age can be something between, e.g., 25 and 35. thirty-one would not work, since it is too accurate for the intended vagueness.)
Er ist 30 Jahre alt. – He is 30 years old.
(He is exactly 30 years old. If he were 31 years old, you would write “31 years”; so 31 would work as well.)
Sie gingen anderthalb Kilometer. – They walked one and a half kilometers.
(Vague information – they walked something between 1.25 and 1.75 kilometers, and even that may be only the best guess.)
Sie gingen 1,5 km. – They walked 1.5 km.
(Accurate information – They walked something between 1.45 km and 1.55 km and this is certain. Of course, you usually do need such an accuracy in this kind of text.)
In both cases, the style should not switch in the middle of a list or similar:
Fahrzeuge mit 6 bis 23 Sitzen. – Vehicles with 6 to 23 seats.