Current extraction methods often extract DNA and RNA separately, and few methods are capable of co-extracting DNA and RNA from sputum. We established a nucleic acid co-extraction method from sputum based on magnetic beads and optimized the method by evaluating influencing factors, such as the guanidinium thiocyanate (GTC) and dithiothreitol (DTT) concentrations, magnetic bead amount, incubation temperature, lysis buffer pH and RNA carrier type. The feasibility of the simultaneous nucleic acid co-extraction method was evaluated by amplifying DNA and RNA viruses from a single clinical specimen with a multiplex RT-qPCR method. Both DNA and RNA were most efficiently extracted when the GTC and DTT concentrations were 2.0 M and 80 mM, respectively, 20 μl magnetic beads were added, the incubation temperature was 80 °C, the pH was 8 or 9, and RNA carrier A was used. Therefore, we established a simple method to extract nucleic acids from two important respiratory viruses compared with other commercial kits. This magnetic beads-based co-extraction method for sputum followed by a multiplex RT-qPCR can rapidly and precisely detect DNA and RNA viruses from a single clinical specimen and has many advantages, such as decreased time, low cost, and a lack of harmful chemicals.