Your Number Is Up

What does the idiom “Your Number Is Up” mean?

Definition:

You are going to die (or suffer some bad misfortune or setback).

For example:

“When his squadron was surrounded, the soldier thought his number was up.”