Portuguese flag

Trilho vs. carril

The primary difference between trilho and carril regarding railroad tracks is regional usage. generally speaking, trilho is the term used in Brazilian Portuguese, while carril is the standard term in European Portuguese (Portugal).

Trilho

B1
In Brazil, trilho is the standard word for the metal bar or track that trains and trams run on. In Portugal, while understood, trilho is predominantly used to mean a hiking trail, path, or track, rather than the metal machinery.
O trem descarrilou porque havia um problema no trilho.
(The train derailed because there was a problem with the rail.)
Os operários estão consertando os trilhos antigos.
(The workers are fixing the old rails.)
Não ande pelos trilhos, é muito perigoso.
(Do not walk along the rails, it is very dangerous.)
O som das rodas de aço no trilho é inconfundível.
(The sound of steel wheels on the rail is unmistakable.)
Precisamos colocar este projeto de volta nos trilhos.
(We need to get this project back on the rails.)

Carril

B2
In Portugal, carril is the technical and common word used to describe the metal rail of a railway line. In Brazil, this word is considered archaic or rare when referring to trains, though it may refer to small grooves or sliding mechanisms in furniture.
O comboio circula sobre o carril de ferro.
(The train runs upon the iron rail.)
A equipe de manutenção limpou a neve do carril.
(The maintenance crew cleared the snow from the rail.)
Foi detetada uma fissura no carril principal.
(A crack was detected in the main rail.)
A distância entre cada carril determina a bitola.
(The distance between each rail determines the gauge.)
Este tipo de carril suporta comboios de alta velocidade.
(This type of rail supports high-speed trains.)

Summary

Use trilho if you are speaking Brazilian Portuguese. Use carril if you are speaking European Portuguese. While both refer to the metal track, swapping them can sound unnatural or foreign depending on the country you are in.