Cron Expressions Explained: A Beginner's Guide with Examples

Cron is the time-based job scheduler used in Unix-like operating systems. If you need to run a script at midnight every day, send a report every Monday morning, or clean up temporary files every hour, cron is the tool for the job. The catch is its compact syntax, which looks cryptic until you understand the pattern. This guide breaks it down field by field.

The Five Fields

A standard cron expression consists of five fields separated by spaces. Each field represents a unit of time:

minute  hour  day-of-month  month  day-of-week
  • Minute — 0 to 59
  • Hour — 0 to 23 (24-hour format)
  • Day of month — 1 to 31
  • Month — 1 to 12 (or JAN-DEC)
  • Day of week — 0 to 7 (0 and 7 are both Sunday, or SUN-SAT)

The expression is read left to right. For example, 30 9 * * * means "at minute 30, hour 9, every day of the month, every month, every day of the week" — in other words, every day at 9:30 AM.

Special Characters

Asterisk (*)

Means "every" for that field. * * * * * runs every minute of every hour of every day.

Comma (,)

Lists multiple values. 0 9,17 * * * runs at 9:00 AM and 5:00 PM every day.

Hyphen (-)

Defines a range. 0 9-17 * * * runs at the top of every hour from 9:00 AM through 5:00 PM.

Slash (/)

Defines a step or interval. */5 * * * * runs every 5 minutes. 0 */2 * * * runs every 2 hours at the top of the hour.

Practical Examples

Here are cron expressions for common scheduling needs:

Every 5 Minutes

*/5 * * * *

Useful for health checks, queue processors, or metrics collection.

Daily at Midnight

0 0 * * *

The classic daily job. Database backups, log rotation, and report generation often run at midnight.

Every Monday at 8:00 AM

0 8 * * 1

Weekly reports, team notifications, or automated Monday-morning emails.

Weekdays Only at 9:00 AM

0 9 * * 1-5

The range 1-5 covers Monday through Friday. Useful for business-hours tasks.

First Day of Every Month at 6:00 AM

0 6 1 * *

Monthly billing, subscription renewals, or monthly reports.

Every 15 Minutes During Business Hours

*/15 9-17 * * 1-5

Combines a step interval with hour and day-of-week ranges. Runs every 15 minutes from 9 AM to 5 PM, Monday through Friday.

First Monday of Every Month at 9:00 AM

This one is tricky because cron does not have a built-in "first Monday" concept. The common workaround is:

0 9 1-7 * 1

This runs on every Monday that falls within the first 7 days of the month — which is always exactly one Monday. Note that in standard cron, day-of-month and day-of-week are OR-ed (not AND-ed), so this approach actually requires your scheduling system to AND them, or you add a check inside your script.

Twice a Day at 8 AM and 8 PM

0 8,20 * * *

The comma separates two specific hours.

Crontab vs Kubernetes CronJob Syntax

Standard Unix crontab uses the five-field format described above. Kubernetes CronJobs use the same five-field syntax, so the expressions are identical. However, there are some differences in behavior:

  • Timezone — crontab runs in the system's local timezone. Kubernetes CronJobs default to the kube-controller-manager timezone (typically UTC) unless you explicitly set a timezone using the timeZone field (supported since Kubernetes 1.27).
  • Concurrency — crontab happily starts a new instance even if the previous one is still running. Kubernetes CronJobs have a concurrencyPolicy field (Allow, Forbid, Replace) to control this.
  • Missed jobs — if a cron machine is down, missed jobs are simply skipped. Kubernetes has a startingDeadlineSeconds field to handle missed schedules.

Some systems use extended six-field or seven-field cron syntax that adds seconds or year fields. AWS CloudWatch Events (now EventBridge) and Quartz scheduler are examples. Always check which format your specific platform expects.

Tips for Writing Cron Expressions

  • Always test before deploying. Use a visual builder or expression explainer to verify your expression does what you think it does. A misplaced field can turn a daily job into one that runs every minute.
  • Comment your crontab entries. Add a comment above each line explaining what the job does and why it runs at that schedule.
  • Consider timezones. If your users are in different timezones, make sure your cron jobs run at the right time for the intended audience.
  • Stagger jobs. Avoid scheduling everything at exactly midnight or the top of the hour. Spread jobs across different minutes to avoid resource contention.

Build cron expressions visually

Use our interactive cron builder to create, test, and understand cron expressions — no memorization needed.

Open Cron Builder