The alkali dicyanamides M[N(CN)2] (M=K, Rb) were synthesized through ion exchange, and the corresponding tricyanomelaminates M3[C6N9] were obtained by heating the respective dicyanamides. The thermal behavior of the dicyanamides and their reaction to form the tricyanomelaminates were investigated by temperature-dependent X-ray powder diffractometry and thermoanalytical measurements. Potassium dicyanamide K[N(CN)2] was found to undergo four phase transitions: At 136 degrees C the low-temperature modification alpha-K[N(CN)2] transforms to beta-K[N(CN)2], and at 187degrees C the latter transforms to the high-temperature modification gamma-K[N(CN)2], which melts at 232 degrees C. Above 310 degrees C the dicyanamide ions [N(CN)2]- trimerize and the resulting tricyanomelaminate K3[C6N9] solidifies. Two modifications of rubidium dicyanamide have been identified: Even at -25 degrees C, the a form slowly transforms to beta-Rb[N(CN)2] within weeks. Rb[N(CN)2] has a melting point of 190 degrees C. Above 260 degrees C the dicyanamide ions [N(CN)2]- of the rubidium salt trimerize in the melt and the tricyanomelaminate Rb3[C6N9] solidifies. The crystal structures of all phases were determined by powder diffraction methods and were refined by the Rietveld method. alpha-K[N(CN)2] (Pbcm, a = 836.52(1), b = 46.90(1), c =7 21.27(1) pm, Z = 4), gamma-K[N(CN)2] (Pnma, a = 855.40(3), b = 387.80(1), 1252.73(4) pm, Z = 4), and Rb[N(CN)2] (C2/c, a = 1381.56(2), b = 1000.02(1), c = 1443.28(2) pm, 116.8963(6) degrees, Z = 16) represent new structure types. The crystal structure of beta-K[N(CN)2] (P2(1/n), a = -726.92(1), b 1596.34(2), c = 387.037(5) pm, 111.8782(6) degrees, Z = 4) is similar but not isotypic to the structure of alpha Na[N(CN)2]. alpha-Rb[N(CN)2] (Pbcm, a = 856.09(1), b = 661.711(7), c = 765.067(9) pm, Z = 4) is isotypic with alpha-K[N(CN)2]. The alkali dicyanamides contain the bent planar anion [N(CN)2]- of approximate symmetry C2, (average bond lengths: C-N(bridge) 133, C-N(term) 113 pm; average angles N-C-N 170 degrees, C-N-C 120 degrees). K3[C6N9] (P2(1/c), a = 373.82(1), b = 1192.48(5), c = 2500.4(1) pm, beta = 101.406(3) degrees, Z = 4) and Rb,[C6N9] (P2(1/c), a = 389.93(2), b = 1226.06(6), c = 2547.5(1) pm, 98.741(5) degrees, Z=4) are isotypic and they contain the planar cyclic anion [C6N9]3-. Although structurally related, Na3[C6N9] is not isotypic with the tricyanomelaminates M3[C6N9] (M = K, Rb).