A basic Spanish spelling rule: whenever you hear a nasal sound (m or n) before a p or b, you have to write m. For example, the first time you hear the word sombrero (hat), you might not be sure if you heard an m or an n sound before the b, but the rule tells us it has to be spelled with an m.
Un sombrero. Listones. Mire qué listones más bonitos
A hat. Ribbons. Look at what beautiful ribbons
para que se haga unos moños.
so that one can make some [hair] buns.
Captions 15-17, El Ausente - Acto 1 - Part 6Play Caption
This rule must be applied without exception. When a word that ends in an n is combined with a word that begins with a p or b to form a compound word like cien+pies → ciempiés (centipede) the n becomes an m. Some other examples of this are en+pollo (chicken) → empollar (to sit on eggs, to hatch), en+bala (bundle) → embalar (to pack) and en+belesa (the belesa is a narcotic plant) → embelesar (to captivate).
Vamos a empollar veinte criaturas
Let's hatch twenty children
Caption 16, Calle 13 - Tango del pecadoPlay Caption
Take note, this rule doesn’t apply to v, despite the fact that native Spanish speakers often conflate it with b. In fact, in Spanish, it is also a rule that you should always write n before v.
La gente no me parecía...
The people didn't seem to...
no me parecía el tipo de gente
they didn't seem to be the kind of people
con el que yo me quería involucrar.
I wanted to get involved with.
Captions 80-81, Arturo Vega - Entrevista - Part 2Play Caption
This rule is very useful when trying to figure out the proper way to spell certain Spanish words, especially considering that it is not uncommon to hear native speakers replace the m sound with an n sound. Listen to our Nicaraguan friend, Doña Coco:
Y hay mucho cristia'... este... católicos también.
And there's a lot of Christia'... I mean... Catholics also.
Caption 28, Doña Coco - MúsicaPlay Caption