Magnetron discharge plasma was applied for the synthesis of CN x thin layers using methane and nitrogen gas precursors. The incorporation of nitrogen in the carbon network resulted in the dramatic evolution of growth morphology: from a ‘buried’ porous layer observed at low nitrogen incorporation to aligned bundles of nanorods grown perpendicular to the substrate surface at maximum discharge power and nitrogen flow. The films deposited at the low discharge power and high nitrogen incorporation exhibited a mesoporous sponge-like morphology after vacuum annealing. Relevant physical mechanisms responsible for the formation of nano- and mesoshaped morphology are discussed in terms of the effects of internal mechanical stresses and plasma etching. In addition, the sensing properties of the sponge-like layer were preliminarily examined in water vapor and ammonia ambients. The CN x films showed enhanced sensitivity to ammonia and reverse electrical response to moisture in comparison with a nitrogen-free nanoporous carbon film, which were assigned to modification of the electronic properties of the nitridated surface.