Question: I have a Nikon D3200 and just started shooting in Raw.

Raw files are 18-24mb, and if I convert them to JPEG using Nikon's ViewNX 2, I get 8-12mb files at the top quality and resolution using sRGB; the same size that I would get out-of-camera shooting in JPG with the maximum quality.

Instead using Darktable with the same options (quality 100 and sRGB at the maximum resolution), I get files of 25-30mb, which is a lot — even more than the original Raw. 

Is there a reason for that? How can I change it? If it's not possible to change, which setting would you advise me to use in Darktable to get smaller files without loosing too much quality?

Answer: 
It seems that the large file size is expected for the settings you chose.

When I take a NEF image from a Nikon D5100 and convert it to JPEG using the sRGB colour space and quality 100, the result is about 18MB in size. Doing the same with dcraw and ImageMagick's convert also leads to a 18MB file.

JPEG 100 quality should probably be never needed. If you want lossless files, use TIFF. For display JPEG 100 is not needed, you can safely use something like 95 and not be able to tell the difference.

What JPEG compression to pick can be researched further and there are questions about this here, but picking a value in the 90s will significantly reduce the size and be fit for purpose for most applications.
The discrepancy in size between JPEGs encoded at "100% quality" in different encoders is likely to be a result of one of the following:

* Different chroma sub-sampling setting. Chroma sub-sampling in JPEGs reduces the spatial resolution of the chroma channels in return for reducing the file size with little noticeable different in quality, at least of most photographic material.

Different JPEG encoders may adjust the chroma sub-sampling differently: some may adjust it along with the quality setting, so a higher quality will also use less sub-sampling. Some may use a different, separate control to the quality setting. And some may not allow any adjustment to this setting at all.
* Differences between how encoders interpret the quality setting. Different JPEG encoders will apply different meanings to the quality setting, so you can't compare quality settings between different encoders.

For example, 80% quality in one encoder may choose similar average quantizer values to 92% quality in another encoder. The quality settings is only indirectly influencing the algorithm that the encoder uses to choose quantizer values for each block in the image. Under the hood, it's these quantizer values that actually affect the quality, and you can't usually adjust these directly.

Even the "100%" quality setting can mean different things between encoders. In some it means to use the lowest quantizers available (preserving the most detail). In others it might not necessarily go that far, or it may (as mentioned above) affect other aspects of the encoding such as the chroma sub-sampling.

Note that the JPEG image will never be *larger* in size than the uncompressed bitmap image, for any normal image. However, comparing it to a RAW file can be a bit misleading since a RAW file would need [several steps](https://photo.stackexchange.com/a/8361/3422) (including a step called *demosaicing*, which will increase size due to interpolation) to expand it out to a proper uncompressed bitmap image.