NAD(P)H pyrophosphatase that hydrolyzes NADH into NMNH and AMP, and NADPH into NMNH and 2',5'-ADP (PubMed:28755312). Has a marked preference for the reduced pyridine nucleotides (PubMed:28755312). Does not show activity toward NAD-capped RNAs; the NAD-cap is an atypical cap present at the 5'-end of some RNAs (PubMed:31101919). H2O + NADH = AMP + 2 H(+) + reduced beta-nicotinamide D-ribonucleotide H2O + NAD(+) = AMP + beta-nicotinamide D-ribonucleotide + 2 H(+) H2O + NADPH = adenosine 3',5'-bisphosphate + 2 H(+) + reduced beta-nicotinamide D-ribonucleotide Divalent metal cations. Mg(2+) or Mn(2+). kcat is 7 sec(-1) for NADH. Optimum pH is 7.8-8.2. Belongs to the Nudix hydrolase family.