μαθαίνω κάτι means "I learn" something
μαθαίνω κάτι σε κάποιον means "I teach"something to someone.
Examples:
μαθαίνω Ελληνικά = I learn Greek.
μαθαίνω τον κανόνα = I learn the rule.
μαθαίνω κάτι απέξω = I learn something by heart.
μαθαίνω να οδηγώ = I learn how to drive.
μαθαίνω από τα λάθη μου =I learn from my mistakes.
μαθαίνω Αγγλικά στο φίλο μου = I teach English to my friend.
μαθαίνω στο γιο μου να οδηγεί = I teach to my son how to drive.
σπουδάζω means "I am a student at university, or college". It refers to academic studies.
Examples:
Σπουδάζω ιατρική. = I study medicine.
Σπουδάζω μαθηματικά. = Ι study mathematics. (I am a student at university)
Σπουδάζω στο πανεπιστήμιο της Αθήνας.= I am a student at the university of Athens.
About your examples:
I am a student in δημοτικό / γυμνάσιο = είμαι μαθητής στο δημοτικό/ γυμνάσιο
I will study until midnight tonight = Θα μελετήσω (or θα διαβάσω) μέχρι τα μεσάνυχτα απόψε.
(μελετάω or διαβάζω here mean "study my homework")
I am taking a course in Mathematics. = Παρακολουθώ μαθήματα μαθηματικών.
---------------------------------------------------------------------------------------------------------------------------
Vasiliki Baskou, Instructor/Director, https://learn-greek-online.com.