panic: runtime error: integer divide by zero Go Origin: Application & API Last updated 4 Nov 2026

Go: panic: runtime error: integer divide by zero

Integer division or modulo by zero.

Exact message you may see panic: runtime error: integer divide by zerointeger divide by zeroruntime error: integer divide by zero goroutine
Seen on: Go

Meaning

Floating-point division by zero yields Inf/NaN, but integer division panics. Validate the divisor, especially values from user input, lengths, or counters (total / count).

Common causes

  • Divisor derived from len() of an empty slice
  • User input zero
  • Counter not incremented
  • Uninitialised struct field used as divisor
  • Modulo by zero

⚡ Quick fix

  1. Check if d == 0 { return error }
  2. Use float division if Inf is acceptable
  3. Validate input at boundaries

Detailed fix by platform

Go

  1. if count == 0 { return 0, errors.New("empty") }; avg := sum / count

How to diagnose

  1. Divisor — Zero when?
  2. Source — Input or length?
  3. Guard — Missing?

🔧 Still not fixed?

Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:

Where this error sits

Origin: Application & API. Errors that are often confused with or caused by this one (click to open):

fatal error: stack overflow — Go: runtime: goroutine stack exceeds 1000000000-byte limit — fatal error: stack overflow (Go)fatal error: stack ov…invalid memory address or nil pointer dereference — Go: panic: runtime error: invalid memory address or nil pointer dereference (Go)invalid memory addres…panic: assignment to entry in nil map — Go: panic: assignment to entry in nil map (Go)panic: assignment to …panic: interface conversion — Go: panic: interface conversion: interface {} is string, not int (Go)panic: interface conv…panic: runtime error: index out of range — Go: panic: runtime error: index out of range [3] with length 3 (Go)panic: runtime error:…panic: slice bounds out of range — Go: panic: runtime error: slice bounds out of range [:5] with capacity 3 (Go)panic: slice bounds o…reflect: call of reflect.Value.X on zero Value — Go: panic: reflect: call of reflect.Value.Elem on zero Value (Go)reflect: call of refl…panic: ru…

Explore the map of this error Full error map →

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.

💬 What worked for others

No tips yet — did something else fix this for you?

Share what worked for you

Tips are checked by an editor before they appear. Links are removed.